zoukankan      html  css  js  c++  java
  • 使用VS2003 发送Email

    使用VS2003发送Email与之后VS2005版本及以上VS版本不一样,记录一下,

    需要引用using System.Web.Mail;

    public void SendEmail()
        {
            try
            {
                //Tools.WriteLog("==============开始发送邮件==============");
                MailMessage mail = new MailMessage();
                //设置接收邮箱 (群发邮箱之间用","英文逗号隔开)
                mail.To = "接收者邮箱地址";
                //设置发送邮箱
                mail.From = "发送者邮箱地址";
                //设置支持服务器验证
                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.Subject = "我的邮件";
                //发送邮件内容
                mail.Body = "这是我发送的邮件";
                //邮件内容格式
                mail.BodyFormat = MailFormat.Html;
                //邮件内容编码
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                //邮件等级
                mail.Priority = MailPriority.High;
                //添加邮件附件
                mail.Attachments.Add(new MailAttachment("D:/1.txt", MailEncoding.Base64));
                #region 可以传入一个ArrayList 存放附件地址,发送多个附件
                //ArrayList mailAttachments = new ArrayList();
                //mailAttachments.Add("path");
                //for (int i = 1; i < mailAttachments.Count + 1; i++)
                //{
                //    if (System.IO.File.Exists(mailAttachments[i - 1].ToString()))
                //    {
                //        mail.Attachments.Add(new MailAttachment(mailAttachments[i - 1].ToString(), MailEncoding.Base64));
                //    }
                //}
                #endregion
                //设置邮件发送smtp服务器
                SmtpMail.SmtpServer = "smtp.qq.com";
                //发送
                SmtpMail.Send(mail);
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "');</script>");
            }
    
        }
    我的人生我做主
  • 相关阅读:
    python实战===教你用微信每天给女朋友说晚安
    [go]beego获取参数/返回参数
    [go]os.Open方法源码
    [go]从os.Stdin探究文件类源码
    [svc]linux中的文件描述符(file descriptor)和文件
    [net]tcp和udp&socket
    [django]update_or_create使用场景
    [sh]shell语法小结
    [drf]访问文档出现错误'AutoSchema' object has no attribute 'get_link'
    [py]python操作zookeeper
  • 原文地址:https://www.cnblogs.com/BinaryStone/p/3466961.html
Copyright © 2011-2022 走看看