Trouble with SendMail body | Selenium Forum
M
Posted on 19/05/2016
Dear All,

I am having trouble with SendMail.sendMail logic and I attached the script below for your review. I am able to get the attachment working, subject working but the body is not working. I can not insert any message in the body area of the email.

Thank you for your help.

M
Replied on 20/05/2016

you can use this

[code:2457sist]package com.soapuitutorial.propertie;
//http://www.vogella.de/articles/JavaRegularExpressions/ar01s05.html
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class Mailer {

public static void main(String[] args) {
final String username = "vaibhavcool12312@yahoo.com";
final String password = "Pass@123";
final String recipient = "appiumselendroid@gmail.com";
final String subject = "message-subject";
final String emailmessage = "message";

Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.mail.yahoo.com");
props.put("mail.smtp.port", "25");

Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});

try {

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient));
message.setSubject(subject);
message.setText(emailmessage);

Transport.send(message);

System.out.println("Done");

} catch (MessagingException e) {
throw new RuntimeException(e);
}

}

}
[/code:2457sist]