Results 1 to 3 of 3
Thread: JavaMail help needed
- 08-26-2010, 01:36 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 3
- Rep Power
- 0
JavaMail help needed
Hi this is the error message im getting...
Cannot send email: javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. z55sm3960650eeh.21
please help....
The code im sending is:
public void sendEmail(final String p_fromEmailAdd, final String[] p_toEmailAddresses, String p_emailSubject, String p_emailBody)
{
String host = "smtp.gmail.com";
String from = "username";
String pass = "password";
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
List<InternetAddress> x_emailAddressesList = new ArrayList<InternetAddress> ();
for (String str : p_toEmailAddresses)
{
try
{
x_emailAddressesList.add(new InternetAddress(str));
} catch (AddressException e)
{
e.printStackTrace();
}
}
Address[] x_toEmailAddresses = (InternetAddress[]) x_emailAddressesList.toArray(new InternetAddress[x_emailAddressesList.size()]);
try
{
message.addRecipients(Message.RecipientType.TO, x_toEmailAddresses);
message.setSubject(p_emailSubject);
message.setContent(p_emailBody, "text/html");
Transport transport = session.getTransport("smtp");
transport.connect(host, 587, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
catch(MessagingException ex)
{
System.err.println("Cannot send email: " + ex);
}
}
- 08-26-2010, 02:46 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
This question has been asked and answered before; search these forums for STARTTLS and you'll find the thread.
kind regards,
Jos
- 08-26-2010, 02:47 PM #3
Member
- Join Date
- Aug 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Javamail
By johniem in forum New To JavaReplies: 0Last Post: 07-14-2010, 03:00 PM -
JavaMail API
By eponcedeleon in forum Advanced JavaReplies: 1Last Post: 02-28-2010, 12:39 AM -
JavaMail Jar
By rummy in forum Advanced JavaReplies: 1Last Post: 01-21-2010, 03:51 PM -
Javamail
By v_mallikarjun in forum Advanced JavaReplies: 14Last Post: 04-18-2008, 07:32 PM -
Using JavaMail API
By consult4u in forum NetworkingReplies: 0Last Post: 08-09-2007, 10:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks