A command line tool for sending emails through Gmail SMTP using gradle and groovy
This is a command line tool for sending messages through the normal SMTP Gmail service - in other words, what your email client might be doing if you use SMTP, but from the command line.
I needed to send emails when certain things happen in some servers I have for personal stuff, and I didn't want to deal with mail services.
gmail-sender is built using groovy and gradle, but neither of them need to be installed. You do need an installed JVM or docker to use it.
Assuming you have a shell with a valid
JAVA_HOME environment variable, enter the project's directory and execute:
./gradlew sendMail -Pusername=yourGmailEmail -Ppassword=yourGmailPassword -Ptofirstname.lastname@example.org,email@example.com -Psubject='The subject' -Pbody='Some <strong>HTML</strong> body to love'
Assuming you have a shell with
docker in the path, enter the project's directory and execute:
docker run -it --rm -v $HOME/docker-dotgradle:/root/.gradle -v (pwd):/app java bash -c 'cd /app && ./gradlew sendMail -Pusername=yourGmailEmail -Ppassword=yourGmailPassword -Ptofirstname.lastname@example.org,email@example.com -Psubject="The subject" -Pbody="Some <strong>HTML</strong> body to love"
This will create a
$HOME/docker-dotgradle directory with the gradle wrapper and the maven dependencies. You can adjust it to whatever you want (even
$HOME/.gradle if you are using gradle in the host machine).
As a maven dependency in another Java based project
You'll need to add
http://deigote.github.io/maven/ as a maven repo, and
com.deigote:gmail-sender:0.1 as a dependency. Once done, you can use GmailSender#instance and then GmailSender#send to send an email, building first the Email and the Credentials.