C# 发邮件

    public static bool Send(string SMTP, string mailFrom, string mailTos, string subject, string body, string user, string paw, MailPriority Priority = MailPriority.Normal)
    {
        MailMessage mailObj = new MailMessage();
        mailObj.From = new MailAddress(mailFrom);//发信人地址
        string[] strarray = mailTos.Split(';');
        foreach (string str in strarray)
        {
            mailObj.To.Add(str);//收信地址
        }
        mailObj.Subject = subject;//邮件标题
        mailObj.Body = body;
        //html格式的邮件
        mailObj.IsBodyHtml = true;
        ////设置为高级优先权(可设可不设)
        mailObj.Priority = Priority;
        //使用SmtpMail对象发送邮件
        SmtpClient smtp = new SmtpClient(SMTP);
        smtp.Credentials = new NetworkCredential(user, paw);
        smtp.Send(mailObj);
        return true;
    }

 

posted @ 2015-10-30 13:31  bobo-bobo  阅读(165)  评论(0编辑  收藏  举报