[JBoss jBPM] - Re: Error while attempting to send mail
by sagyer
"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(a)lntinfotech.com";
| String to = "sagar.yerunkar(a)lntinfotech.com";
| String cc = "sagyer(a)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
16 years, 4 months