# Send email via task and groovy script

**URL:** <https://community.sonatype.com/t/send-email-via-task-and-groovy-script/938>\
**Category:** Sonatype Nexus Repository\
**Tags:** groovy\
**Created:** [December 12, 2018, 1:39pm UTC](https://community.sonatype.com/t/send-email-via-task-and-groovy-script/938 "2018-12-12T13:39:34Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![jschneider](https://yyz1.discourse-cdn.com/flex047/user_avatar/community.sonatype.com/jschneider/32/378_2.png) [@jschneider](https://community.sonatype.com/u/jschneider)\
**Post date:** [December 12, 2018, 1:39pm UTC](https://community.sonatype.com/t/send-email-via-task-and-groovy-script/938/1 "2018-12-12T13:39:34Z")

</div>

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 !

---

_[View the full topic](https://community.sonatype.com/t/send-email-via-task-and-groovy-script/938)._
