Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in mailing with smtp server

Sekhar Chand
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai friends,

i wrote one standalone program to send a mail using gmail smtp server.
The program is

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class Main
String d_email = "",
d_password = "****",
d_host = "",
d_port = "465",
m_to = "tomailaddress",
m_subject = "Testing",
m_text = "Hey, this is the testing email.";

public Main()
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("", d_host);
props.put("mail.smtp.port", d_port);
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", d_port);
props.put("mail.smtp.socketFactory.class", "");
props.put("mail.smtp.socketFactory.fallback", "false");

//SecurityManager security = System.getSecurityManager();

Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);

MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));
catch (Exception mex)

public static void main(String[] args)
Main blah = new Main();

private class SMTPAuthenticator extends javax.mail.Authenticator
public PasswordAuthentication getPasswordAuthentication()
return new PasswordAuthentication(d_email, d_password);

Here one exception is raised.

That exception is

javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: Could not connect to SMTP host: smt, port: 465;
nested exception is: Couldn't connect using "
ory" socket factory to host, port:, 465; Exception: java.lang.ref
at javax.mail.Transport.send0(
at javax.mail.Transport.send(
at Main.<init>(
at Main.main(

can any one tell me what is the problem.
thanks in advance
Kaywin Dcosta
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check any firewall is enabled for this host
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic