June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
47
Task/Send-email/Groovy/send-email.groovy
Normal file
47
Task/Send-email/Groovy/send-email.groovy
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import javax.mail.*
|
||||
import javax.mail.internet.*
|
||||
|
||||
public static void simpleMail(String from, String password, String to,
|
||||
String subject, String body) throws Exception {
|
||||
|
||||
String host = "smtp.gmail.com";
|
||||
Properties props = System.getProperties();
|
||||
props.put("mail.smtp.starttls.enable",true);
|
||||
/* mail.smtp.ssl.trust is needed in script to avoid error "Could not convert socket to TLS" */
|
||||
props.setProperty("mail.smtp.ssl.trust", host);
|
||||
props.put("mail.smtp.auth", true);
|
||||
props.put("mail.smtp.host", host);
|
||||
props.put("mail.smtp.user", from);
|
||||
props.put("mail.smtp.password", password);
|
||||
props.put("mail.smtp.port", "587");
|
||||
|
||||
Session session = Session.getDefaultInstance(props, null);
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(from));
|
||||
|
||||
InternetAddress toAddress = new InternetAddress(to);
|
||||
|
||||
message.addRecipient(Message.RecipientType.TO, toAddress);
|
||||
|
||||
message.setSubject(subject);
|
||||
message.setText(body);
|
||||
|
||||
Transport transport = session.getTransport("smtp");
|
||||
|
||||
transport.connect(host, from, password);
|
||||
|
||||
transport.sendMessage(message, message.getAllRecipients());
|
||||
transport.close();
|
||||
}
|
||||
|
||||
/* Set email address sender */
|
||||
String s1 = "example@gmail.com";
|
||||
|
||||
/* Set password sender */
|
||||
String s2 = "";
|
||||
|
||||
/* Set email address sender */
|
||||
String s3 = "example@gmail.com"
|
||||
|
||||
/*Call function */
|
||||
simpleMail(s1, s2 , s3, "TITLE", "TEXT");
|
||||
Loading…
Add table
Add a link
Reference in a new issue