A simple program to send mail
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   abc_xyz
Posted On:   Tuesday, March 26, 2002 08:13 AM

A simple program to send mail

Re: A simple program to send mail

Posted By:   Jyothis_E  
Posted On:   Wednesday, March 27, 2002 02:36 AM

Hi! ABCXYZ,
here is a program that send a mail and attachment.... hope this come handy ;)
Love, Je


import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class sendmail4 {
public static void main (String args[]) throws Exception {
String host = "xxx.xxx.xxx.xxx";//replace with the smtp host
String from = "you@urdomain.com";
String to = "she@herdomain.com";
filename="heart.gif"


Properties props = System.getProperties();


props.put("mail.smtp.host", host);


Session session = Session.getInstance(props, null);


Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("I Love you");


BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("Here's the Heart, as an Attachment!!! ");

Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);

messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);

message.setContent(multipart);
Transport.send(message);
}
}

About | Sitemap | Contact