System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
System.Web.Mail.MailAttachment mailAttach_1 = null;
mailAttach_1 = new System.Web.Mail.MailAttachment("文件路径");
mail.Attachments.Add(mailAttach_1);
mail.To = "收件箱";
mail.From = "发件箱";
mail.Subject = "打印报告";
mail.BodyFormat = System.Web.Mail.MailFormat.Html;
mail.Body = "如果不希望接收此台打印机的更多信息,请联系打印机所有人!!";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //身份验证
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "发件箱"); //邮箱登录账号,这里跟前面的发送账号一样就行
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "发件箱密码"); //这个密码要注意:如果是一般账号,要用授权码;企业账号用登录密码
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//端口
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");//SSL加密
System.Web.Mail.SmtpMail.SmtpServer = "smtp.qiye.aliyun.com"; //企业账号用smtp.exmail.qq.com
System.Web.Mail.SmtpMail.Send(mail); |