Hi all !
I created a groovy script which remove oldest components of a maven release repo. It is schedule by a task in Nexus administration.
I want to improve this script by sending notification of incoming deletion (some days before).
My issue : how could i send email from this script ?
I tried:
import javax.mail.*
import javax.mail.internet.*
....
private boolean sendMail(){
def d_email = "email@email.com",
d_host = "smtpo365",
d_port = "25",
m_to = "email@email.com",
m_subject = "Testing",
m_text = "Hey, this is the testing email."
def props = new Properties()
props.put("mail.smtp.user", d_email)
props.put("mail.smtp.host", d_host)
props.put("mail.smtp.port", d_port)
props.put("mail.smtp.starttls.enable","false")
props.put("mail.smtp.debug", "true");
props.put("mail.smtp.auth", "false")
props.put("mail.smtp.socketFactory.port", d_port)
//props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory")
props.put("mail.smtp.socketFactory.fallback", "false")
def auth = new SMTPAuthenticator()
def session = Session.getInstance(props, auth)
session.setDebug(true);
def msg = new MimeMessage(session)
msg.setText(m_text)
msg.setSubject(m_subject)
msg.setFrom(new InternetAddress(d_email))
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to))
Transport transport = session.getTransport("smtps");
transport.connect(d_host, d_port);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
}
....
Result :
unable to resolve class SMTPAuthenticator
def auth = new SMTPAuthenticator()
Do somebody have an idea of my mistake or a way to do this email sending ?
Thanks alot !