Selenium Web驱动程序:如何使用java在电子邮件中包含testNG的可通过电子邮件报告的详细信息

时间:2013-06-17 11:07:03

标签: java selenium selenium-webdriver

我已经编写了下面提到的代码,用于使用java在电子邮件中附加TestNG的可通过电子邮件发送的报告。 现在我想用java.Anyone对这个电子邮件正文中粘贴可邮寄报告的详细信息吗?

import java.io.IOException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendMailSSL {
    public static void main(String[] args) {

         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            final Properties props = new Properties();
            try {
                props.load(classLoader.getResourceAsStream("Mail/Credentials.properties"));
                String Username = props.getProperty("username");
                String Password= props.getProperty("password");
            } catch (IOException e) {
                e.printStackTrace();
            }
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.host", "x");
            props.put("mail.smtp.port", "25");



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

            try {

                Message message = new MimeMessage(session);
                message.setFrom(new InternetAddress("x"));
                message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("x"));
                message.setSubject("Testing Subject");
                message.setText("Dear Mail Crawler,"
                    + "\n\n No spam to my email, please!");

                Transport.send(message);

                System.out.println("Done");

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

0 个答案:

没有答案