08 Jun 2017

Selenium – Sending email via Gmail SMTP

Selenium, Testing 0 Comment

How to send a mail through SMTP server using Java programming, it’s bulk process to send test cases(Screenshots, Description. text ) to many emails by manually so using JavaMail API it can be possible to send many users at a time.

This article will show you how to send a mail through SMTP server using java programming and follow below steps.

1. Create Maven Project
2. For sending the email using JavaMail API, you need to load the two jar files:

  • mail.jar
  • activation.jar

Download zip file

3. Project structure




IMP: Before running the script we need to enable one option, follow below steps.

Note: This is only for FROM Mail address. Where we can send emails FROM and TO addresses.

Click on My account > Sign-in & security
Scroll down the page and then we should enable this ” Allow less secure apps: ON ” option otherwise, we will get exceptions.

One more point is will see this option only for new emails, not for old emails. it means email should be created recently.

Note: All set for running the code, right click on ” TestMail.java ” and run as JavaApplication.

You have successfully sent the mail.

Thanks for reading this article!