This repository has been archived by the owner on Jun 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7be3cf9
commit 619531f
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.hawkcd.utilities; | ||
|
||
import javax.mail.Message; | ||
import javax.mail.MessagingException; | ||
import javax.mail.Session; | ||
import javax.mail.Transport; | ||
import javax.mail.internet.InternetAddress; | ||
import javax.mail.internet.MimeMessage; | ||
import java.util.Properties; | ||
|
||
public class MailService { | ||
public static void sendMail() { | ||
// Recipient's email ID needs to be mentioned. | ||
String to = "[email protected]"; | ||
|
||
// Sender's email ID needs to be mentioned | ||
String from = "[email protected]"; | ||
|
||
// Assuming you are sending email from localhost | ||
String host = "localhost"; | ||
|
||
// Get system properties | ||
Properties properties = System.getProperties(); | ||
|
||
// Setup mail server | ||
properties.setProperty("mail.smtp.host", "smtp.gmail.com"); | ||
|
||
// Get the default Session object. | ||
Session session = Session.getDefaultInstance(properties); | ||
|
||
try { | ||
// Create a default MimeMessage object. | ||
MimeMessage message = new MimeMessage(session); | ||
|
||
// Set From: header field of the header. | ||
message.setFrom(new InternetAddress(from)); | ||
|
||
// Set To: header field of the header. | ||
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); | ||
|
||
// Set Subject: header field | ||
message.setSubject("This is the Subject Line!"); | ||
|
||
// Now set the actual message | ||
message.setText("This is actual message"); | ||
|
||
// Send message | ||
// Transport transport = session.getTransport("smtp"); | ||
// transport.connect(null, login, pass); | ||
Transport.send(message); | ||
System.out.println("Sent message successfully...."); | ||
} catch (MessagingException mex) { | ||
mex.printStackTrace(); | ||
} | ||
} | ||
} |