码迷,mamicode.com
首页 > Windows程序 > 详细

C#发送邮件功能的实现

时间:2015-05-13 10:12:02      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

该随便主要是记录下面的方法,便于以后方便查找;

public string GetSendEmail(string from, string to, string smtp, string password, string subject, string body)
        {
            try
            {
                LogRecord.Write(null, "from:" + from + ";to:" + to + ";smtp:" + smtp + ";password:" + password + ";subject:" + subject);
                LogRecord.Write(null, "body参数为:" + body);
                var bodyArr = body.Split(|);
                if (bodyArr.Length != 11)
                {
                    LogRecord.Write(null, "" + to + "发邮件状况:参数的数据不对");
                    return "body参数的数据不对";
                }
                var bodyAll = @"
<div class=‘main‘>
    <p class=‘tx_center‘><span>XX集团面试通知</span></p>
    <p>" + bodyArr[0] + @"您好!感谢您对本公司的关注!您的简历已通过我们初步筛选,现诚邀您来我公司参加面试 。</p>
    <p>您面试职位是:<span class=‘color_r‘>" + bodyArr[1] + @"</span></p>
    <p>您面试时间是:<span class=‘color_r‘>" + bodyArr[2] + @"<span class=‘color_r‘></span></p>
    <p>面试注意事项:<span class=‘color_r‘>" + bodyArr[3] + @"</span><span class=‘color_r‘></span></p>
    <p>面试地点:<span class=‘color_r‘>" + bodyArr[4] + @"</span></p>
    <p>公司详细地址:<span class=‘color_r‘>" + bodyArr[5] + @"</span></p>
    <p>乘车路线:<span class=‘color_r‘>" + bodyArr[6] + @"</span></p>
    <p><span class=‘color_r‘>简单地图:<br/><img src=‘" + bodyArr[7] + @"‘ /></span></p>
    <p>请您届时准时参加!若有问题或变化请致电,电话号码:" + bodyArr[8] + @",联系人:" + bodyArr[9] + @"或邮箱说明,谢谢!</p>
    <p>瑞祥集团简介:</p>
    <p>公司网址 : " + bodyArr[10] + @"</p>
</div>";
                LogRecord.Write(null, "内容为:" + bodyAll);

                var message = new MailMessage(from, to, subject, bodyAll)
                {
                    BodyEncoding = Encoding.Default,
                    IsBodyHtml = true,
                    Priority = MailPriority.High
                };
                LogRecord.Write(null, "发送前");
                var client = new SmtpClient(smtp)
                {
                    UseDefaultCredentials = false,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    Credentials = new System.Net.NetworkCredential(from, password)
                };
                client.Send(message);
                LogRecord.Write(null, "" + to + "发邮件状况:true");
                return "true";
            }
            catch (Exception e)
            {
                LogRecord.Write(e, e.Message);
                return e.Message;
            }
        }

 

C#发送邮件功能的实现

标签:

原文地址:http://www.cnblogs.com/liuqichun/p/4499467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!