J
jrefactors
I want the Java application to send email using google gmail account.
The following is the output, and it cannot display "sendMail() 3..."
in the following sendMail() method. The program just hangs after
printing "sendMail() 2...", and there is no errors.
output
===============
sendMail()...
sendMail() 2...
Basically it get stucks on line
transport.connect(smtpHost, 465, "gmail account", "gmail password");
----------------------------------------------------------
public void sendMail() throws MessagingException
{
System.out.println("sendMail()...");
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "465");
// props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
MimeMessage message = new MimeMessage(session);
message.setFrom(from);
Iterator itrto = toRecipients.iterator();
while(itrto.hasNext())
{
Object obj = (Address)itrto.next();
if(obj instanceof Address){
message.addRecipient(Message.RecipientType.TO, (Address)obj);
}
}
System.out.println("sendMail() 2...");
message.setSubject(subject);
message.setContent(msgText, "text/plain");
Transport transport = session.getTransport("smtp");
//***** GET STUCK HERE!!! ******
transport.connect(smtpHost, 465, "gmail account", "gmail password");
System.out.println("sendMail() 3...");
Transport.send(message);
System.out.println("sendMail() 4...");
}
The following is the output, and it cannot display "sendMail() 3..."
in the following sendMail() method. The program just hangs after
printing "sendMail() 2...", and there is no errors.
output
===============
sendMail()...
sendMail() 2...
Basically it get stucks on line
transport.connect(smtpHost, 465, "gmail account", "gmail password");
----------------------------------------------------------
public void sendMail() throws MessagingException
{
System.out.println("sendMail()...");
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "465");
// props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
MimeMessage message = new MimeMessage(session);
message.setFrom(from);
Iterator itrto = toRecipients.iterator();
while(itrto.hasNext())
{
Object obj = (Address)itrto.next();
if(obj instanceof Address){
message.addRecipient(Message.RecipientType.TO, (Address)obj);
}
}
System.out.println("sendMail() 2...");
message.setSubject(subject);
message.setContent(msgText, "text/plain");
Transport transport = session.getTransport("smtp");
//***** GET STUCK HERE!!! ******
transport.connect(smtpHost, 465, "gmail account", "gmail password");
System.out.println("sendMail() 3...");
Transport.send(message);
System.out.println("sendMail() 4...");
}