I am trying to send email through java using this code :
package send_email;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
/**
*
* @author A
*/
public class Send_email {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String host="smtp.gmail.com";
final String user="***@gmail.com";//change accordingly
final String password="****";//change accordingly
String to="*******@gmail.com";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user,password);
}
});
//Compose the message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("javatpoint");
message.setText("This is simple program of sending email using JavaMail API");
//send the message
Transport.send(message);
System.out.println("message sent successfully...");
} catch (MessagingException e) {e.printStackTrace();}
}
}
But I get the following error :
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25, response: 554
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1694)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
at javax.mail.Service.connect(Service.java:313)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
at send_email.Send_email.main(Send_email.java:48)
BUILD SUCCESSFUL (total time: 0 seconds)
I have allowed port 25 through firewall and then I have tested it using telnet " telnet smtp.gmail.com 25 " but I get this error 554 OutgoingFilter "You are temporarily deferred due to sending spam or virus pl ease contact 16333 for more information"
So how do I fix this error?