如何发送邮件并添加附件
怎样利用自己的邮件(hotmail).在代码中自动发送邮件.在网上看了好多例子.自己也试了.就是不成功..求底特律...
MailAddress from = new MailAddress("zeroccj@hotmail.com","ryan.chu"); //邮件的发件人
MailMessage mail = new MailMessage();
//设置邮件的标题
mail.Subject = "maliSubject";//txtSubject.Text;
//设置邮件的发件人
//Pass:如果不想显示自己的邮箱地址,这里可以填符合mail格式的任意名称,真正发mail的用户不在这里设定,这个仅仅只做显示用
mail.From = from;
//设置邮件的收件人
string address = "150691175@qq.com";
string displayName = "xxx";
mail.To.Add(new MailAddress(address,displayName));
//设置邮件的内容
mail.Body = "mailbody";//txtBody.Text;
//设置邮件的格式
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
//设置邮件的发送级别
mail.Priority = MailPriority.Normal;
string fileName = @"E:\dianli\Out\test.xlsx";
mail.Attachments.Add(new Attachment(fileName));
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;