File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Give me solution to send mail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Give me solution to send mail" Watch "Give me solution to send mail" New topic

Give me solution to send mail

venkata redddy kesari

Joined: Mar 01, 2006
Posts: 2
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendApp {

public static void send(String smtpHost, int smtpPort,
String from, String to,
String subject, String content)
throws AddressException, MessagingException {

// Create a mail session
java.util.Properties props = new java.util.Properties();
props.put("", smtpHost);
props.put("mail.smtp.port", ""+smtpPort);
Session session = Session.getDefaultInstance(props, null);

// Construct the message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));

// Send the message

public static void main(String[] args) throws Exception {
// Send a test message
send("", 465, "", "",
"Hello", "Hello, \n\n How are you ?");


i am getting erroe like this, i use above one.

---------- java ----------
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first h20sm1335140wxd

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(
at com.sun.mail.smtp.SMTPTransport.mailFrom(
at com.sun.mail.smtp.SMTPTransport.sendMessage(
at javax.mail.Transport.send0(
at javax.mail.Transport.send(
at simplemail.send(
at simplemail.main(

Output completed (2 sec consumed) - Normal Termination
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
while obtaining the session use the following code (You use null)

Also you may set the following in props

I agree. Here's the link:
subject: Give me solution to send mail
It's not a secret anymore!