Hi all,
I am able to send mail to my office account but when I try to send it to out side i.e my yahoo id, I am unable to receive the mail . It does not give any error message also..
and here is the email sender.
Thanks to all in advance..
I am able to send mail to my office account but when I try to send it to out side i.e my yahoo id, I am unable to receive the mail . It does not give any error message also..
Code:
Email email = new Email();
email.setContent("Test Email");
email.setReceipient(user.getUserID());
email.setReceipientEmail("myID@yahoo.com");
email.setSubject("Test subject " );
email.setSentDate(new Date(System.currentTimeMillis()));
try {
EmailSender.sendEmail(email);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
and here is the email sender.
Code:
public static void sendEmail( Email email ) throws MessagingException, UnsupportedEncodingException {
//String SYSTEM_EMAIL = SystemProperties.getProperty("system.emailAddress");
//String SYSTEM_NAME = SystemProperties.getProperty("system.emailDisplay");
String SYSTEM_EMAIL = "karthik@starry-associates.com";
String SYSTEM_NAME = "starry-associates.com";
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
/* props.put("mail.smtp.host", SystemProperties.getProperty("system.mailServer"));
props.put("mail.host", SystemProperties.getProperty("system.mailServer")); */
props.put("mail.smtp.host", "mail01");
props.put("mail.host", "mail01");
log.debug(props.toString());
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
MimeMessage msg = new MimeMessage(session);
// set the from address and full name
InternetAddress addrFrom = new InternetAddress(SYSTEM_EMAIL, SYSTEM_NAME);
msg.setFrom(addrFrom);
// set the replyTo address
InternetAddress[] addrReplyTo = new InternetAddress[1];
addrReplyTo[0] = new InternetAddress(SYSTEM_REPLY_TO);
msg.setReplyTo(addrReplyTo);
// set the TO address
InternetAddress[] addrTo = new InternetAddress[1];
addrTo[0] = new InternetAddress(email.getReceipientEmail());
msg.setRecipients(Message.RecipientType.TO, addrTo);
// Setting the Subject and Content Type
msg.setSubject(email.getSubject());
msg.setContent(email.getContent(), "text/html");
// setting the Flag or Priority
if (email.isFlagged()) {
Flags flags = new Flags();
flags.add(Flag.FLAGGED);
msg.setFlags(flags, true);
msg.addHeader("Priority", "Urgent");
msg.addHeader("Importance", "high");
}
// properly set the sent date
msg.setSentDate(new Date(System.currentTimeMillis()));
log.debug("Sending email from "+email.getSender());
//String mailServer = SystemProperties.getProperty("system.mailServer");
//String account = SystemProperties.getProperty("system.mailAccount");
//String passwd = SystemProperties.getProperty("system.mailPassword");
String mailServer = "mail01";
String account = "karthik";
String passwd = "4321";
if (passwd==null) passwd="";
// using the non-static version so we can connect with a NULL password
Transport transport = session.getTransport("smtp");
transport.connect(mailServer, account, passwd);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
}
Thanks to all in advance..