Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

AuthenticatedFailedException is thrown javamail

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
The following Code works fine,but once in a while i am getting authentication failedexception even if i am setting properties for authentication to true and including authenticator mentioned in the comments
please help me to solve this problem
Dinakar

code is mentioned below

import java.security.Security;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Main
{
private static final String SMTP_HOST_NAME = "smtp.mycompanyname.com";
private static final String SMTP_PORT = "25";
private static final String emailMsgTxt = "Test Message Contents";
private static final String emailSubjectTxt = "A test from gmail";
private static final String emailFromAddress = "checkit@mycompanyname.com";
private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
private static final String[] sendTo = {"mymailid@gmail.com"};

public static void main(String args[]) throws Exception {

System.out.println("ok");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
try{
new Main().sendSSLMessage(sendTo, emailSubjectTxt,emailMsgTxt, emailFromAddress);
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Sucessfully Sent mail to All Users");
}//end of mainmethod

public void sendSSLMessage(String recipients[], String subject,String message, String from) throws MessagingException,AuthenticationFailedException
{
boolean debug = true;
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "false");
//props.put("mail.smtp.ehlo","true");
//props.put("mail.debug", "false");
//props.put("mail.smtp.port", SMTP_PORT);
//props.put("mail.smtp.socketFactory.port", SMTP_PORT);

//props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
//props.put("mail.smtp.socketFactory.fallback", "false");
Session session = Session.getDefaultInstance(props,null);
/* new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("uhelpme@mycompanyname.com","asdafd");
}}; */
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport transport = session.getTransport("smtp");
transport.connect();
//transport.connect("uhelpme@mycompanyname.com","abcdefghi");
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();

//Transport.send(msg);
}//end of sendsslmessage
}//end of class
reply
    Bookmark Topic Watch Topic
  • New Topic