mercredi 26 novembre 2014

JAVA Email not working properly


Vote count:

0




I am using this code to send mail from inside spring application



public static void main( final String[] args ) throws MessagingException
{
System.out.println("<port> <username> <password> <to>");
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.mydomain.in");
props.put("mail.smtp.port", args[0].trim());

Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(args[1].trim(),args[2].trim());
}
});

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(args[1].trim()));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(args[3]));
message.setSubject("test mail");
message.setContent("test mail body","text/html");
Transport.send(message);
}


Scanerio where it works



  • If i run it in my local system

  • If i use it withing my spring application on my local machine

  • If i run it alone in AWS


Where it doesn't work




  • If i use it withing my spring application on AWS it throws



    throws javax.mail.MessagingException'.
    javax.mail.AuthenticationFailedException: 535 5.7.8 Error: authentication failed: authentication failure

    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)




asked 22 secs ago

Manish

968






JAVA Email not working properly

Aucun commentaire:

Enregistrer un commentaire