getting can't determine local email address Exception while sending mail from java
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, March 16, 2010 02:16 AM

import javax.mail.*; import javax.activation.*; import java.util.Properties; import javax.mail.internet.*; public class smtpsend { private static final String SMTP_HOST_NAME = "smtp.gmail.com"; private static final String SMTP_AUTH_USER = "rockysingh399"; private static final String SMTP_AUTH_PWD = "07592233016"; private static final String emailMsgTxt = "Please visit my project "; private static final String emailSubjectTxt = "Ticket Tracker"; private static final String[] emailSendToList = { "sweetyinsearch@gmail.com","kimmy.6401@gmail.com" }; public static void main(String args[]) throws Except   More>>

import javax.mail.*;
import javax.activation.*;
import java.util.Properties;
import javax.mail.internet.*;
public class smtpsend
{

private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final String SMTP_AUTH_USER = "rockysingh399";
private static final String SMTP_AUTH_PWD = "07592233016";
private static final String emailMsgTxt = "Please visit my project ";
private static final String emailSubjectTxt = "Ticket Tracker";
private static final String[] emailSendToList = { "sweetyinsearch@gmail.com","kimmy.6401@gmail.com" };
public static void main(String args[]) throws Exception
{

smtpsend smtpMailSender = new smtpsend();
smtpMailSender.postMail(emailSendToList, emailSubjectTxt, emailMsgTxt);
System.out.println("Sucessfully Sent mail to All Users");
}

public void postMail(String recipients[], String subject, String message) throws MessagingException
{
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.user", "rockysingh399@gmail.com");
props.put("mail.password", "07592233016");
//props.put("mail.smtp.sendpartial", "true");
props.put("mail.smtp.allow8bitmime","true");



// "base64", "quoted-printable", "7bit", "8bit", "binary"

Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(true);
Message msg = new MimeMessage(session);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);System.out.println(addressTo[i]);
}
msg.addRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(subject);

msg.saveChanges();
msg.setContent(message, "type/html;charset=utf-8");

Transport.send(msg);
}


private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
}
}


}e


Please use html tags to format code blocks.

   <<Less
About | Sitemap | Contact