: This message was edited by teddyj at 2004-8-9 7:27:27
Thank you I have My java Mail working. I will use your example and compare it with mine to see the difference.
Thank you for your time.
: : Go through the following code carefully. This program is developed by me and running. Please don't forget to change the email addresses and smtp server's host,port names before compiling the program.
: :
: :
: :
: : import javax.mail.Message;
: : import javax.mail.Session;
: : import javax.mail.Transport;
: : import javax.mail.URLName;
: : import javax.mail.internet.InternetAddress;
: : import javax.mail.internet.MimeMessage;
: :
: : import com.sun.mail.smtp.SMTPTransport;
: :
: : public class TextMailSender {
: :
: : private Transport tr;
: : private Message msg;
: : private Session sn;
: : public void setMessage(String fromAddress,String toAddress,
: : String subject,String content) throws Exception {
: : String[] addresses = {toAddress};
: : setMessage(fromAddress,addresses,subject,content);
: : }
: :
: : public void setMessage(String fromAddress,String[] toAddresses,
: : String subject,String content) throws Exception {
: :
: : sn = Session.getInstance(System.getProperties());
: :
: :
: : msg = new MimeMessage(sn);
: : msg.setFrom(new InternetAddress(fromAddress));
: : InternetAddress[] toIntAdds = new InternetAddress[toAddresses.length];
: :
: : for (int i=0;i<toAddresses.length;i++)
: : toIntAdds[i] = new InternetAddress(toAddresses[i]);
: :
: : msg.setRecipients(Message.RecipientType.TO,toIntAdds);
: : msg.setSubject(subject);
: : msg.setSentDate(new java.util.Date());
: : msg.setText(content);
: : }
: :
: : public void setSMTPServer(String host,int port,
: : String user,String password) throws Exception{
: : tr = new SMTPTransport(sn,new URLName(host));
: : tr.connect(host,port,null,null);
: : }
: :
: : public void send() throws Exception{
: : msg.saveChanges();
: : tr.sendMessage(msg, msg.getAllRecipients());
: : tr.close();
: : }
: :
: : public static void main(String[] args) throws Exception{
: : TextMailSender tms = new TextMailSender();
: : tms.setMessage("swapan_java_api_prog@swapan.net.uk",
: : new String[]{"jitesh.india@mailbox123.com","dey_swapan@swapan2.com"},"test mail","Boss, I am sendingthis mail from my java program. " +
: : "The from id doesn't exists but you can reply this mail to my official id");
: : tms.setSMTPServer("localhost",25,null,null);
: : tms.send();
: : }
: : }
: :
:
:
:
:
:
: