Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hu.icell.testing.helper.restful;
- import javax.mail.*;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import java.util.Properties;
- public class MailAPI {
- private static final String USERNAME = "david.urban@icellmobilsoft.hu";
- private static final String PASSWORD = "nelunuiqhjbbgmtp";
- public MailAPI(String log) {
- sendMail(log);
- }
- public void sendMail(String log) {
- String host = "smtp.gmail.com";
- Properties props = new Properties();
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.host", host);
- props.put("mail.smtp.port", "587");
- Session session = Session.getInstance(props,
- new javax.mail.Authenticator() {
- @Override
- 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(USERNAME));
- message.setSubject("Testing subjejct");
- message.setText(log);
- Transport.send(message);
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement