[jboss-user] [JBoss jBPM] - Re: Error while attempting to send mail

sagyer do-not-reply at jboss.com
Thu Aug 28 23:34:14 EDT 2008


"kukeltje" wrote : seems to have nothing to do with jBPM. Can you send email from java at all?

Yes, I can send mail from java from the same machine. Here is the code that sends the mail. I have tested this code and it works :


  | 	public static void main(String[] args) throws AddressException,
  | 			MessagingException {
  | 
  | 		String smtpHost = "172.25.8.13";
  | 
  | 		String from = "sagar.yerunkar at lntinfotech.com";
  | 		String to = "sagar.yerunkar at lntinfotech.com";
  | 		String cc = "sagyer at gmail.com";
  | 		String bcc = "";
  | 		String message = "Test Mail";
  | 		String subject = "Test Subject";
  | 
  | 		Properties props = new Properties();
  | 		props.put("mail.smtp.host", smtpHost);
  | 		Session session = Session.getInstance(props);
  | 
  | 		// Instantiate a message
  | 		Message msg = new MimeMessage(session);
  | 
  | 		// Set message attributes
  | 		msg.setFrom(new InternetAddress(from));
  | 		InternetAddress[] address = { new InternetAddress(to) };
  | 
  | 		msg.setRecipients(Message.RecipientType.TO, address);
  | 		if (!("".equals(cc))) {
  | 			InternetAddress[] addresscc = { new InternetAddress(cc) };
  | 			msg.setRecipients(Message.RecipientType.CC, addresscc);
  | 		}
  | 		if (!("".equals(bcc))) {
  | 			InternetAddress[] addressbcc = { new InternetAddress(bcc) };
  | 			msg.setRecipients(Message.RecipientType.BCC, addressbcc);
  | 		}
  | 		msg.setSubject(subject);
  | 		msg.setSentDate(new Date());
  | 
  | 		// Set message content
  | 		msg.setText(message);
  | 		// ////////////////////////////////////////
  | 
  | 		// Send the message
  | 		Transport.send(msg);
  | 
  | 		System.out.println("Sent mail successfully");
  | 
  | 	}
  | 
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4173217#4173217

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4173217



More information about the jboss-user mailing list