C#发送邮件功能的实现

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

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;
            }
        }

 

转载于:https://www.cnblogs.com/liuqichun/p/4499467.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值