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:
TEXT-TO-SQL · AI ANALYTICS SECURITYText-to-SQL Securityin AI BI ToolsInjection · Exposure · Testing Text-to-SQL Security in AI BI Tools: Stop Prompt Injection and Data Over-ExposureThe risks of letting a language model write queries against your database, and the layered controls...
Introduction: Is Your BI Platform Ready for the Next Stage of Analytics? Business intelligence has evolved beyond creating charts and dashboards. Organizations now expect their analytics platforms to help employees discover insights, investigate business performance, distribute reports, and integrate data...
PRESS RELEASE A Fully Free Open Source BI Platform With AI Analytics: Helical Insight Opens Enterprise Features to Everyone HYDERABAD, TELANGANA, INDIA — August 2026 Helical Insight, the open source business intelligence and embedded analytics platform developed by Hyderabad-based Helical...