Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

simple mail program

843834Dec 3 2007 — edited Dec 4 2007
dear friends , i am new to this api and i tried to execute one simple program , which compiled well , but reported exception , it was some thing related to host i am attaching the source code, the problem it related to String host and string from , i use a dail up connection , what should i use instead of "xyz.net" and "abc.net"



import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class Simple
{
public static void main(String args[])
{
String host ="xyz.net";
String to="programarunesh@gmail.com";
String from="abc.net";
String subject="hjgf";
String messageText="hello";
boolean sessionDebug=false;
Properties props=System.getProperties();
props.put("mail.host",host);
props.put("mail.tranport.protocol","smtp");
Session session=Session.getDefaultInstance(props,null);
session.setDebug(sessionDebug);
try
{
Message msg=new MimeMessage(session);
InternetAddress[] address={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.to,address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
Transport.send(msg);
}
catch(MessagingException mex)
{
mex.printStackTrace();
}}}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 1 2008
Added on Dec 3 2007
2 comments
123 views