| |
| javamail 发送附件的例子 |
| |
发布者: 发布时间:2007-09-23 |
|
|
import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*;
public class AttachExample { public static void main (String args[]) throws Exception { String host = args[0]; String from = args[1]; String to = args[2]; String fileAttachment = args[3];
// Get system properties Properties props = System.getProperties();
// Setup mail server props.put("mail.smtp.host", host);
// Get session Session session = Session.getInstance(props, null);
// Define message MimeMessage message = new MimeMessage(session); message.setFrom( new InternetAddress(from)); message.addRecipient( Message.RecipientType.TO, new InternetAddress(to)); message.setSubject( "Hello JavaMail Attachment");
// create the message part MimeBodyPart messageBodyPart = new MimeBodyPart();
//fill message messageBodyPart.setText("Hi");
Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart);
// Part two is attachment messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(fileAttachment); messageBodyPart.setDataHandler( new DataHandler(source)); messageBodyPart.setFileName(fileAttachment); multipart.addBodyPart(messageBodyPart);
// Put parts in message message.setContent(multipart);
// Send the message Transport.send( message ); } }
|
| (转载文章请保留出处:北天JAVA技术网(www.java114.com)) |
| |
| 更多精彩文章: |
| 把JavaMail包装成简单的Sendmail |
| 用javamail进行认证发信 |
| Java电子邮件 |
| JSP与JavaMail (一) |
| JSP与JavaMail (二) |
| JSP与JavaMail (四) |
| |
| 最近评论: |
|
|
| 鍥炲 |
|
|
|
| 如果真的有来生! |
| 四川旅游,九寨沟旅游,稻城亚丁旅游,四姑娘山旅游,海螺沟旅游,西藏旅游,
max(6067) |
|
|
| 那天的情景! |
| Maple Story mesos,MapleStory mesos,ms mesos,mesos,SilkRoad Gold,
max(4541) |
|
|
| 轻轻走过你的窗前! |
| world of warcraft gold,cheap world of warcraft gold,warcraft gold,world of warcraft gold,cheap world of warcraft gold,warcraft gold max(4206) |
|
|
| 不在的哪天! |
| final fantasy xi gil,final fantasy xi gil,final fantasy xi gil,final fantasy xi gil,
max(8512) |
|
|
| 不在的哪天! |
| final fantasy xi gil,final fantasy xi gil,final fantasy xi gil,final fantasy xi gil,
max(7044) |
|
|
| 快乐情人节! |
| wow gold,wow gold,wow gold,wow gold,wow gold,wow gold,wow gold buy wow gold for cheap.
max(268) |
|
|
| 昨夜的狂想曲! |
| wow gold,WoW Gold,world of warcraft gold,WoW Gold, max(8661) |
|
|
| 没有情人的情人节! |
| wow gold,wow power leveling.wow power leveling,wow power leveling,
max(5018) |
|
|
| 不想在乎你! |
| dofus kamas,dofus kamas,EVE ISK,dog shoes,pet supply,
max(9511) |
|
|
| |
| 免责声明:该文章由网友发表,如果对您造成侵权,请联系站长。 |
|
|