Wednesday, 15 August 2012

java - Exception in thread "main" javax.mail.SendFailedException: Invalid Addresses; -


Trying to send a mail to my SMTP mail server I work with Spring based code while working it perfectly But when I'm trying to send via Java code, my Java code is:

  import java.util.Properties; Import javax.mail.Message; Import javax.mail.MessagingException; Import javax.mail.Session; Import javax.mail.Transport; Import javax.mail.internet.AddressException; Import javax.mail.internet.InternetAddress; Import javax.mail.internet.MimeMessage; Public Class Test1 {Properties Email Properties = New Properties (); Session mail session; MimeMessage Email Messages; Public static zero master throws the address exception, messaging exception JavaEmail.setMailServerProperties (); JavaEmail.createEmailMessage (); JavaEmail.sendEmail (); } Public Zero Settle Server Servers () {string emailport = "587"; String host = "mysmtphost"; EmailProperties.put ("mail.smtp.host", host); EmailProperties.put ("mail.smtp.socketFactory.port", "465"); EmailProperties.put ("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); EmailProperties.put ("mail.smtp.auth", "true"); EmailProperties.put ("mail.smtp.port", emailport); } Public Zero email message () throws email address = {"tomail.com"} from addressing, messaging exception {string []; String Email Subject = "Java Email"; String EmailBody = "This is an email sent by the JavaMail API."; Mail session = session .get default instances (e-mail, properties, blank); Println ("mailSession" + mailSession); Email Message = New MimeMessage (Mail Session); For (int i = 0; i & lt; tomeels langhal; i ++) {email message. Eder Reciprint (Message RecipeType.To, New Internet Address (At Emails)); } EmailMessage.setSubject (emailSubject); Email message for an email. Content content (emailbod, "text / html"); // Send an email to //emailMessage.setText (mailbox); // for a text message; Send public ZeroAmail () forward addressing, messaging exception {String emailHost = "mysmtphost"; String cius = "myusername"; String cuisineEmail password = "mypassword"; Transportation Transport = mailSession.getTransport ("smtp"); Transport.connect (emailhost, from user, with user e-mail password); System.out.println ("Connect to server"); Transport.sendMessage (email message, email message. GET ALLRecipients ()); Transport.close (); System.out.println ("Email Successfully Sent."); }}  

And when the Java application is running, the following exception is being made:

  Exceptions in the thread "main" javax.mail. SendFailedException: Invalid address; The nested exception is: Class javax.mail.SendFailedException: 554 5.7.1 & lt; Unknown [172.18.140.85] & gt ;: Client host rejected: com.sun.mail.smtp.SMTPTransport.rcptTo access denied (SMTPTransport.java:926) Com.sun.mail.smtp.SMTPTransport.sendMessage At (SMTPTransport.java:389) at com.cmc.test. Test1.send email (test1.java:76) at com.cmc.test. Test1.main (Test1 Java: 28)  

To get the "connected to server" line in my console.

Please help me, if anyone has come into this type of problem. Waiting for response.

Thank you

The message is very clear:

 < Code> class javax.mail.SendFailedException: 554 5.7.1 & lt; Unknown [172.18.140.85] & gt ;: Client host disapproved: denied access  

Add authentication information to you.


No comments:

Post a Comment