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:
hi
Posted by suresh on December 09, 2000 at 1:51 AM
> 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:
- fail Andy May 22, 2001 at 5:41 PM
(1)
|