├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── README.md ├── license ├── pom.xml └── src └── main └── java └── com └── rawsanj └── mail ├── ConfigConsts.java ├── MailMessageUtils.java ├── MailServers.java ├── SendEmailWithAttachments.java ├── SendGMailTLS.java ├── SendOutlookMailTLS.java ├── SendYahooMailTLS.java └── SendZohoMailTLS.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | 11 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 12 | !/.mvn/wrapper/maven-wrapper.jar 13 | 14 | ### STS ### 15 | .apt_generated 16 | .classpath 17 | .factorypath 18 | .project 19 | .settings 20 | .springBeans 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | .idea/ 28 | mail.iml 29 | src/main/java/com/rawsanj/mail/CredentialsConstants.java 30 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mail 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 3 | org.eclipse.jdt.core.compiler.compliance=1.5 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.5 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # java-mail-clients 2 | 3 | 4 | #### This demo is created to test the Java Mail Clients, to configure MailService is [jHipster] application as suggested in jHipster Tip - [Configuring Email with - Gmail] 5 | 6 | ### Version 7 | 1.1.RELEASE 8 | 9 | ### Note (for Gmail) 10 | You must allow your Gmail account to access less secure apps. 11 | 12 | 13 | Login to Gmail and visit [Here](https://www.google.com/settings/security/lesssecureapps) to Turn On Access for less secure apps. 14 | 15 | [More Info here](https://support.google.com/accounts/answer/6010255) 16 | 17 | ### Installation 18 | 19 | ```sh 20 | $ git clone https://github.com/RawSanj/java-mail-clients.git 21 | ``` 22 | 23 | #### Updated Version (added support for Attachments): 24 | 25 | 1. Update `ConfigConsts.java` file with *to* and *from* Email address and password. 26 | 2. Select the SMTP Server (GMAIL, YAHOO, OUTLOOK or ZOHO) and update the File path where the attachments are located. 27 | 3. Run the `SendEmailWithAttachments` class as Java Application. 28 | 29 | #### Older Version: 30 | 1. Change the `sendToAddress`, `sendFromAddress` and `password` in the respective E-Mail client app and run as Java Application. 31 | 32 | 33 | ### Reference 34 | 35 | Refer below links for API and SMTP settings: 36 | 37 | * [JavaMail API] - JavaMail : version-1.5.4 38 | * [GMail SMTP] - Gmail SMTP Settings. 39 | * [Outlook SMTP] - Outlook SMTP Settings. 40 | * [Yahoo SMTP] - Yahoo SMTP Settings. 41 | * [Zoho SMTP] - Zoho SMTP Settings. 42 | 43 | ### Tools 44 | 45 | The following tools are used to create this project : 46 | 47 | * Eclipse 48 | * Google Chrome 49 | * Git 50 | 51 | 52 | ### License 53 | ---- 54 | 55 | The MIT License (MIT) 56 | 57 | Copyright (c) 2017. Sanjay Rawat 58 | 59 | 60 | [//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax) 61 | 62 | [JavaMail API]: 63 | [GMail SMTP]: 64 | [Outlook SMTP]: 65 | [Yahoo SMTP]: 66 | [Zoho SMTP]: 67 | [jHipster]: 68 | [Configuring Email with - Gmail]: 69 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Sanjay Rawat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.rawsanj 7 | java-mail-clients 8 | 1.1.RELEASE 9 | 10 | 11 | 12 | org.apache.maven.plugins 13 | maven-compiler-plugin 14 | 15 | 1.8 16 | 1.8 17 | 18 | 19 | 20 | 21 | 22 | java-mail-clients 23 | Send Java Email from GMail, Outlook, Yahoo and Zoho. Demo App to test jHipster tip for Email 24 | 25 | 26 | 1.5.4 27 | UTF-8 28 | UTF-8 29 | 1.8 30 | 31 | 32 | 33 | 34 | 35 | com.sun.mail 36 | javax.mail 37 | ${sun-mail.version} 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/com/rawsanj/mail/ConfigConsts.java: -------------------------------------------------------------------------------- 1 | package com.rawsanj.mail; 2 | 3 | public final class ConfigConsts { 4 | 5 | // Recipient's email ID needs to be mentioned. 6 | public static final String TO_EMAIL_ADDRESS = "sendToAddress@example.com"; 7 | 8 | // Sender's email ID needs to be mentioned 9 | public static final String FROM_EMAIL_ADDRESS = "sendFromAddress@gmail.com"; 10 | 11 | // Email address for Login 12 | public static final String USER_NAME_EMAIL = "sendFromAddress@gmail.com"; 13 | 14 | // Email password for Login 15 | public static final String USER_PASSWORD = "********"; 16 | 17 | // Physical Folder Path 18 | public static final String FILE_PATH = "path/to/files"; 19 | 20 | // Set SMTP Server Address - GMAIL, OUTLOOK, YAHOO or ZOHO 21 | public static final String SMPT_HOST_ADDRESS = MailServers.GMAIL.getAddress(); 22 | 23 | // Server name - gets reflected in email message Subject and body 24 | public static final String SMPT_HOST_NAME = MailServers.GMAIL.getName(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/rawsanj/mail/MailMessageUtils.java: -------------------------------------------------------------------------------- 1 | package com.rawsanj.mail; 2 | 3 | import javax.activation.DataHandler; 4 | import javax.activation.DataSource; 5 | import javax.activation.FileDataSource; 6 | import javax.mail.BodyPart; 7 | import javax.mail.MessagingException; 8 | import javax.mail.Multipart; 9 | import javax.mail.internet.MimeBodyPart; 10 | import javax.mail.internet.MimeMultipart; 11 | import java.io.File; 12 | import java.util.List; 13 | 14 | public class MailMessageUtils { 15 | 16 | // Return Multipart Object which holds mail body message and attachment files in BodyParts 17 | public static Multipart messageMultipart(List listOfFlies) throws MessagingException { 18 | 19 | // BodyPart to hold message body 20 | BodyPart messageBody = new MimeBodyPart(); 21 | // Now set the actual message 22 | messageBody.setText("Hello, this is sample email with attachments to check/send " 23 | + "email using JavaMailAPI from "+ ConfigConsts.SMPT_HOST_NAME); 24 | 25 | // Multipart will hold messageBodyPart and attachments 26 | Multipart multipart = new MimeMultipart(); 27 | 28 | // Add Message BodyPart to Multipart 29 | multipart.addBodyPart(messageBody); 30 | 31 | // Add Files to multipart 32 | addFileToMultipart(listOfFlies, multipart); 33 | 34 | return multipart; 35 | } 36 | 37 | // Adding attachment files to Multipart 38 | private static void addFileToMultipart(List listOfFlies, Multipart multipart) { 39 | 40 | listOfFlies.stream() 41 | .filter(file -> file.isFile()) 42 | .forEach(f -> { 43 | try { 44 | multipart.addBodyPart(addAttachment(f)); 45 | } catch (MessagingException e) { 46 | e.printStackTrace(); 47 | } 48 | }); 49 | } 50 | 51 | private static MimeBodyPart addAttachment(File file) throws MessagingException{ 52 | 53 | MimeBodyPart attachmentBodyPart = new MimeBodyPart(); 54 | DataSource source = new FileDataSource(file); 55 | attachmentBodyPart.setDataHandler(new DataHandler(source)); 56 | attachmentBodyPart.setFileName(file.getName()); 57 | 58 | return attachmentBodyPart; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/rawsanj/mail/MailServers.java: -------------------------------------------------------------------------------- 1 | package com.rawsanj.mail; 2 | 3 | public enum MailServers { 4 | 5 | GMAIL("GMAIL", "smtp.gmail.com"), 6 | OUTLOOK("OUTLOOK", "smtp-mail.outlook.com"), 7 | YAHOO("YAHOO", "smtp.mail.yahoo.com"), 8 | ZOHO("ZOHO", "smtp.zoho.com"); 9 | 10 | private final String name; 11 | private final String address; 12 | 13 | MailServers(String name, String address) { 14 | this.address = address; 15 | this.name = name; 16 | } 17 | 18 | public String getName() { 19 | return this.name; 20 | } 21 | 22 | public String getAddress() { 23 | return this.address; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/rawsanj/mail/SendEmailWithAttachments.java: -------------------------------------------------------------------------------- 1 | package com.rawsanj.mail; 2 | 3 | import javax.mail.*; 4 | import javax.mail.internet.InternetAddress; 5 | import javax.mail.internet.MimeMessage; 6 | import java.io.File; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.Properties; 10 | 11 | public class SendEmailWithAttachments { 12 | 13 | public static void main(String[] args) { 14 | 15 | // Set Java Mail Properties 16 | Properties props = new Properties(); 17 | props.put("mail.smtp.auth", "true"); 18 | props.put("mail.smtp.starttls.enable", "true"); 19 | props.put("mail.smtp.host", ConfigConsts.SMPT_HOST_ADDRESS); 20 | props.put("mail.smtp.port", "587"); 21 | props.put("mail.smtp.ssl.trust", ConfigConsts.SMPT_HOST_ADDRESS); 22 | 23 | // Get the Session object. 24 | Session session = Session.getInstance(props, 25 | new Authenticator() { 26 | protected PasswordAuthentication getPasswordAuthentication() { 27 | return new PasswordAuthentication(ConfigConsts.USER_NAME_EMAIL, ConfigConsts.USER_PASSWORD); 28 | } 29 | }); 30 | 31 | // Get all files in Folder 32 | File filesInPath = new File(ConfigConsts.FILE_PATH); 33 | List listOfFlies = Arrays.asList(filesInPath.listFiles()); 34 | 35 | try { 36 | // Create a default MimeMessage object. 37 | Message message = new MimeMessage(session); 38 | 39 | // Set From: header field of the header. 40 | message.setFrom(new InternetAddress(ConfigConsts.FROM_EMAIL_ADDRESS)); 41 | 42 | // Set To: header field of the header. 43 | message.setRecipients(Message.RecipientType.TO, 44 | InternetAddress.parse(ConfigConsts.TO_EMAIL_ADDRESS)); 45 | 46 | // Set Subject: header field 47 | message.setSubject(ConfigConsts.SMPT_HOST_NAME + " - Email Test"); 48 | 49 | // Get Multipart Object with Message Body and Attachments 50 | Multipart multipart = MailMessageUtils.messageMultipart(listOfFlies); 51 | 52 | // Set the multiplart object (message body + files) to the message object 53 | message.setContent(multipart ); 54 | 55 | // Send message 56 | Transport.send(message); 57 | 58 | System.out.println("Sent message successfully.... from "+ ConfigConsts.SMPT_HOST_NAME); 59 | 60 | } catch (MessagingException e) { 61 | throw new RuntimeException(e); 62 | } 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /src/main/java/com/rawsanj/mail/SendGMailTLS.java: -------------------------------------------------------------------------------- 1 | package com.rawsanj.mail; 2 | 3 | import java.util.Properties; 4 | 5 | import javax.mail.Message; 6 | import javax.mail.MessagingException; 7 | import javax.mail.PasswordAuthentication; 8 | import javax.mail.Session; 9 | import javax.mail.Transport; 10 | import javax.mail.internet.InternetAddress; 11 | import javax.mail.internet.MimeMessage; 12 | 13 | public class SendGMailTLS { 14 | public static void main(String[] args) { 15 | // Recipient's email ID needs to be mentioned. 16 | String to = "sendToAddress@example.com";//change accordingly 17 | 18 | // Sender's email ID needs to be mentioned 19 | String from = "sendFromAddress@gmail.com";//change accordingly 20 | 21 | final String username = "sendFromAddress@gmail.com";//change accordingly 22 | final String password = "********";//change accordingly 23 | 24 | // GMail's SMTP server 25 | String host = "smtp.gmail.com"; 26 | 27 | Properties props = new Properties(); 28 | props.put("mail.smtp.auth", "true"); 29 | props.put("mail.smtp.starttls.enable", "true"); 30 | props.put("mail.smtp.host", host); 31 | props.put("mail.smtp.port", "587"); 32 | props.put("mail.smtp.ssl.trust", host); 33 | 34 | // Get the Session object. 35 | Session session = Session.getInstance(props, 36 | new javax.mail.Authenticator() { 37 | protected PasswordAuthentication getPasswordAuthentication() { 38 | return new PasswordAuthentication(username, password); 39 | } 40 | }); 41 | 42 | try { 43 | // Create a default MimeMessage object. 44 | Message message = new MimeMessage(session); 45 | 46 | // Set From: header field of the header. 47 | message.setFrom(new InternetAddress(from)); 48 | 49 | // Set To: header field of the header. 50 | message.setRecipients(Message.RecipientType.TO, 51 | InternetAddress.parse(to)); 52 | 53 | // Set Subject: header field 54 | message.setSubject("Gmail - Email Test"); 55 | 56 | // Now set the actual message 57 | message.setText("Hello, this is sample email to check/send " 58 | + "email using JavaMailAPI from GMAIL"); 59 | 60 | // Send message 61 | Transport.send(message); 62 | 63 | System.out.println("Sent message successfully.... from GMAIL"); 64 | 65 | } catch (MessagingException e) { 66 | throw new RuntimeException(e); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/main/java/com/rawsanj/mail/SendOutlookMailTLS.java: -------------------------------------------------------------------------------- 1 | package com.rawsanj.mail; 2 | 3 | import java.util.Properties; 4 | 5 | import javax.mail.Message; 6 | import javax.mail.MessagingException; 7 | import javax.mail.PasswordAuthentication; 8 | import javax.mail.Session; 9 | import javax.mail.Transport; 10 | import javax.mail.internet.InternetAddress; 11 | import javax.mail.internet.MimeMessage; 12 | 13 | public class SendOutlookMailTLS { 14 | public static void main(String[] args) { 15 | // Recipient's email ID needs to be mentioned. 16 | String to = "sendToAddress@example.com";//change accordingly 17 | 18 | // Sender's email ID needs to be mentioned 19 | String from = "sendFromAddress@outlook.com";//change accordingly 20 | 21 | final String username = "sendFromAddress@outlook.com";//change accordingly 22 | final String password = "********";//change accordingly 23 | 24 | // Outlook's SMTP server 25 | String host = "smtp-mail.outlook.com"; 26 | 27 | Properties props = new Properties(); 28 | props.put("mail.smtp.auth", "true"); 29 | props.put("mail.smtp.starttls.enable", "true"); 30 | props.put("mail.smtp.host", host); 31 | props.put("mail.smtp.port", "587"); 32 | props.put("mail.smtp.ssl.trust", host); 33 | 34 | // Get the Session object. 35 | Session session = Session.getInstance(props, 36 | new javax.mail.Authenticator() { 37 | protected PasswordAuthentication getPasswordAuthentication() { 38 | return new PasswordAuthentication(username, password); 39 | } 40 | }); 41 | 42 | try { 43 | // Create a default MimeMessage object. 44 | Message message = new MimeMessage(session); 45 | 46 | // Set From: header field of the header. 47 | message.setFrom(new InternetAddress(from)); 48 | 49 | // Set To: header field of the header. 50 | message.setRecipients(Message.RecipientType.TO, 51 | InternetAddress.parse(to)); 52 | 53 | // Set Subject: header field 54 | message.setSubject("Outlook - Email Test"); 55 | 56 | // Now set the actual message 57 | message.setText("Hello, this is sample email to check/send " 58 | + "email using JavaMailAPI from Outlook"); 59 | 60 | // Send message 61 | Transport.send(message); 62 | 63 | System.out.println("Sent message successfully.... from Outlook"); 64 | 65 | } catch (MessagingException e) { 66 | throw new RuntimeException(e); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/main/java/com/rawsanj/mail/SendYahooMailTLS.java: -------------------------------------------------------------------------------- 1 | package com.rawsanj.mail; 2 | 3 | import java.util.Properties; 4 | 5 | import javax.mail.Message; 6 | import javax.mail.MessagingException; 7 | import javax.mail.PasswordAuthentication; 8 | import javax.mail.Session; 9 | import javax.mail.Transport; 10 | import javax.mail.internet.InternetAddress; 11 | import javax.mail.internet.MimeMessage; 12 | 13 | public class SendYahooMailTLS { 14 | public static void main(String[] args) { 15 | // Recipient's email ID needs to be mentioned. 16 | String to = "sendToAddress@example.com";//change accordingly 17 | 18 | // Sender's email ID needs to be mentioned 19 | String from = "sendFromAddress@yahoo.com";//change accordingly 20 | final String username = "sendFromAddress@yahoo.com";//change accordingly 21 | final String password = "*******";//change accordingly 22 | 23 | // Yahoo's SMTP server 24 | String host = "smtp.mail.yahoo.com"; 25 | 26 | Properties props = new Properties(); 27 | props.put("mail.smtp.auth", "true"); 28 | props.put("mail.smtp.starttls.enable", "true"); 29 | props.put("mail.smtp.host", host); 30 | props.put("mail.smtp.port", "587"); 31 | props.put("mail.smtp.ssl.trust", host); 32 | 33 | // Get the Session object. 34 | Session session = Session.getInstance(props, 35 | new javax.mail.Authenticator() { 36 | protected PasswordAuthentication getPasswordAuthentication() { 37 | return new PasswordAuthentication(username, password); 38 | } 39 | }); 40 | 41 | try { 42 | // Create a default MimeMessage object. 43 | Message message = new MimeMessage(session); 44 | 45 | // Set From: header field of the header. 46 | message.setFrom(new InternetAddress(from)); 47 | 48 | // Set To: header field of the header. 49 | message.setRecipients(Message.RecipientType.TO, 50 | InternetAddress.parse(to)); 51 | 52 | // Set Subject: header field 53 | message.setSubject("Yahoo - Email Test"); 54 | 55 | // Now set the actual message 56 | message.setText("Hello, this is sample email to check/send " 57 | + "email using JavaMailAPI from Yahoo"); 58 | 59 | // Send message 60 | Transport.send(message); 61 | 62 | System.out.println("Sent message successfully.... from Yahoo"); 63 | 64 | } catch (MessagingException e) { 65 | throw new RuntimeException(e); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /src/main/java/com/rawsanj/mail/SendZohoMailTLS.java: -------------------------------------------------------------------------------- 1 | package com.rawsanj.mail; 2 | 3 | import java.util.Properties; 4 | 5 | import javax.mail.Message; 6 | import javax.mail.MessagingException; 7 | import javax.mail.PasswordAuthentication; 8 | import javax.mail.Session; 9 | import javax.mail.Transport; 10 | import javax.mail.internet.InternetAddress; 11 | import javax.mail.internet.MimeMessage; 12 | 13 | public class SendZohoMailTLS { 14 | public static void main(String[] args) { 15 | // Recipient's email ID needs to be mentioned. 16 | String to = "sendToAddress@example.com";//change accordingly 17 | 18 | // Sender's email ID needs to be mentioned 19 | String from = "sendFromAddress@zoho.com";//change accordingly 20 | 21 | final String username = "sendFromAddress@zoho.com";//change accordingly 22 | final String password = "*******";//change accordingly 23 | 24 | // Zoho's SMTP server 25 | String host = "smtp.zoho.com"; 26 | 27 | Properties props = new Properties(); 28 | props.put("mail.smtp.auth", "true"); 29 | props.put("mail.smtp.starttls.enable", "true"); 30 | props.put("mail.smtp.host", host); 31 | props.put("mail.smtp.port", "587"); 32 | props.put("mail.smtp.ssl.trust", host); 33 | 34 | // Get the Session object. 35 | Session session = Session.getInstance(props, 36 | new javax.mail.Authenticator() { 37 | protected PasswordAuthentication getPasswordAuthentication() { 38 | return new PasswordAuthentication(username, password); 39 | } 40 | }); 41 | 42 | try { 43 | System.out.println("Indisde rty"); 44 | // Create a default MimeMessage object. 45 | Message message = new MimeMessage(session); 46 | 47 | // Set From: header field of the header. 48 | message.setFrom(new InternetAddress(from)); 49 | 50 | // Set To: header field of the header. 51 | message.setRecipients(Message.RecipientType.TO, 52 | InternetAddress.parse(to)); 53 | 54 | // Set Subject: header field 55 | message.setSubject("Zoho - Email Test"); 56 | 57 | // Now set the actual message 58 | message.setText("Hello, this is sample email to check/send " 59 | + "email using JavaMailAPI from Zoho"); 60 | 61 | // Send message 62 | Transport.send(message); 63 | 64 | System.out.println("Sent message successfully.... from Zoho"); 65 | 66 | } catch (MessagingException e) { 67 | System.out.println(e.getMessage()); 68 | throw new RuntimeException(e); 69 | } 70 | } 71 | } --------------------------------------------------------------------------------