message.setText(“Dear Recipient,” +”\n\n Hurray!! Mail is here.”);
Now, Send Message:
Transport.send(message);
NOTE:
If you are trying to send mail using gmail SMTP, first you need to disable security. You can find this option in your gmail setting or when you send mail, you will get one mail from gmail which will help you to disable security.
You can find below the code which sends mail using gmail SMTP:
package com.helical.Mail;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMailGmail {
public static void main(String[] args)
{
final String username = “username@gmail.com”;
final String password = “password”;
Properties props = new Properties();
props.put(“mail.smtp.auth”, “true”);
props.put(“mail.smtp.starttls.enable”, “true”);
props.put(“mail.smtp.host”, “smtp.gmail.com”);
props.put(“mail.smtp.port”, “587”);
Session session = Session.getInstance(props, new javax.mail.Authenticator(){
message.setText(“Dear Recipient,”+ “\n\n Mail has received”);
Transport.send(message);
System.out.println(“Mail Sent Successfully”);
}
catch (MessagingException e)
{
throw new RuntimeException(e);
}
}
}
Troubleshooting:
There are few exception, which you get often:
UnknownHostException : SMTP HOST
Ping to your SMTP host from command line. Make sure you get response (Success) because sometimes your firewall may block your connection.
javax.mail.AuthenticationFailedException
Check your username and password. If this is correct, try to login using your browser and make sure given user information are correct.
Could not connect to SMTP host
Check your SMTP host name and SMTP port, this is correct or not. Execute telnet command from your command prompt and check you are able to connect or not. Telnet command is:
C:\> telnet <SMTP HOST> <SMTP PORT>
Thanks
Sharad Sinha
Best Open Source Business Intelligence Software Helical Insight is Here
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
02 Sept 2024 – Helical IT Solutions is thrilled to announce the release of Helical Insight version 5.2.1, the latest upgrade to its Open Source Business Intelligence (BI) platform. This new version delivers a powerful, cost-effective BI solution that is...
Steps to install firebird db 1. Go to google and type firebird in search box and then click on first link. License aggrement 2. Click on downloads and then install Firebird latest version(5.0.0). 3. It will navigate to the below...
This blog explains about the complete life cycle of a bug and different status of bug from the stage it was identified,fixed,retest and close. What is Defect life cycle? Defect life cycle is the life cycle of a defect or...