Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Program to send mail
Posted by Arun Sacheti on October 13, 2000 at 5:15 PM
Here is a sample code you need the javax.mail package for this. I am using the yahoo smtp server. You can replace it with any other smtp server. import java.util.*; import javax.mail.*; import javax.mail.internet.*; public class MailSend{ public MailSend(){ try{ String smtphost ="smtp.mail.yahoo.com" ; String from = "sacheti@yahoo.com"; String to = "sarcot@yahoo.com" ; // start a session Properties prop = System.getProperties(); prop.put("mail.smtp.host",smtphost); Session session1 = Session.getInstance(prop,null); // construct a message MimeMessage msg = new MimeMessage(session1); msg.setFrom(new InternetAddress(from)); msg.addRecipient(Message.RecipientType.TO,new InternetAddress(to)); msg.setSubject("Example"); msg.setText("from mail program"); // connect to the transport Transport trans = session1.getTransport("smtp"); trans.connect(smtphost,"userid","password"); // send the message trans.sendMessage(msg,msg.getAllRecipients()); //smtphost trans.close(); }catch(Exception e){ e.printStackTrace(); } }// Constructor public static void main(String[] s){ MailSend ms = new MailSend(); } }
Replies:
- mail mohammad January 07, 2002 at 5:34 AM
(0)
- tell me about the javax.mail package prakash June 28, 2001 at 9:40 AM
(1)
- test ariel June 13, 2001 at 4:42 PM
(0)
- Here is a sample code suresh May 19, 2001 at 10:09 AM
(2)
- mail ben May 17, 2001 at 6:28 AM
(0)
- testing Max Engstrom May 14, 2001 at 8:42 AM
(0)
- hai jeya May 01, 2001 at 8:16 AM
(0)
- reply marcduss@hotmal.com April 10, 2001 at 12:13 AM
(0)
- dsfhs sdf April 03, 2001 at 8:55 AM
(0)
- java code felix March 26, 2001 at 5:12 PM
(0)
- Testing Java Mail Aniruddh January 30, 2001 at 7:34 PM
(6)
- proba domian domian January 19, 2001 at 3:00 AM
(0)
- hi suresh December 09, 2000 at 1:51 AM
(2)
- fail Andy May 22, 2001 at 5:41 PM
(1)
- about mail aslam sharief November 29, 2000 at 2:11 AM
(1)
- java mail ��T�w June 06, 2001 at 10:27 PM
(0)
- Hello Georges November 18, 2000 at 2:52 PM
(1)
- java.mail robert April 19, 2001 at 9:33 PM
(0)
|