Aspose Email控件如何管理邮件附件

作者:控件中国网   出处:控件中国网   2015-08-11 10:45:33   阅读:11

附件属于电脑本地文件,该文件会伴随邮件消息一起发送给客户,Aspose Email提供了Attachment类,专门用于管理邮件的附件信息,下面主要介绍Aspose Email控件如何处理邮件附件,具体如下:

1.如何为邮件附上附件
//Create an instance of MailMessage class
MailMessage message = new MailMessage();

//From
message.From = "sender@sender.com";

//to whom
message.To.Add("receiver@gmail.com");

//Adding 1st attachment
//Create an instance of Attachment class
Attachment attachment;

//Load an attachment
attachment = new Attachment(@"E:\1.txt");

//Add attachment in instance of MailMessage class
message.Attachments.Add(attachment);

//Add 2nd Attachment
message.AddAttachment(new Attachment(@"E:\1.jpg"));

//Add 3rd Attachment
message.AddAttachment(new Attachment(@"E:\1.doc"));

//Add 4th Attachment
message.AddAttachment(new Attachment(@"E:\1.rar"));

//Add 5th Attachment
message.AddAttachment(new Attachment(@"E:\1.pdf"));

//Save message to disc
message.Save(@"E:\output.msg",MessageFormat.Msg);

2.删除邮件附件
//Create an instance of Attachment class
Attachment attachment;

//Load attachment to your Mail Message
attachment = new Attachment(@"e:\1.txt");

//Add attachment to your Mail Message
message.Attachments.Add(attachment);

//Remove attachment from your MailMessage
message.Attachments.Remove(attachment);
3.显示邮件附件名
//Create a loop to display the no. of attachments present in email message
foreach (Attachment attachment in message.Attachments)
{

    //Save your attachments here
    attachment.Save("filename");

    //display the the attachment file name
    Console.WriteLine(attachment.Name);

}

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat