This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Give me solution to send mail" Watch "Give me solution to send mail" New topic
Author

Give me solution to send mail

venkata redddy kesari
Greenhorn

Joined: Mar 01, 2006
Posts: 2
import java.io.*;
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("mail.smtp.host", 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));
msg.setSubject(subject);
msg.setText(content);

// Send the message
Transport.send(msg);
}

public static void main(String[] args) throws Exception {
// Send a test message
send("smtp.gmail.com", 465, " venkatareddyk@gmaill.com", " venkatareddykesari@gmail.com",
"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(SMTPTransport.java:1353)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:924)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:553)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at simplemail.send(simplemail.java:27)
at simplemail.main(simplemail.java:34)

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


http://www.skillassert.com


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Give me solution to send mail