C#发送邮件,并发送附件

//邮件内容
        protected void SendEmail()
        {
            try
            {
                //发送邮件,要记得到邮箱中设置接收SMTP邮件
                string strSmtpServer = "mail.vline.net.cn";
                string strFrom = "*******@vline.net.cn";
                string strFromPass = "123456";
                string strto ="*******@vline.net.cn";
                string strSubject = "未来科技保证金到期提醒";

                //strBody
                System.Text.StringBuilder strBody = new System.Text.StringBuilder();
                strBody.Append("亲爱的用户,您好:");
                strBody.AppendLine("<p/>");
                strBody.Append("&nbsp;&nbsp;&nbsp;&nbsp;您有即将到期的信息,具体情况见附件,请尽快查看并予以处理!");
                strBody.Append("&nbsp;&nbsp;&nbsp;&nbsp;该邮件由系统自动发出,请不要回复。");

                SendSMTPEmail(strSmtpServer, strFrom, strFromPass, strto, strSubject, strBody.ToString(),);
            }
            catch ()
            {
            }
        }


        //SMTP发送邮件
        public static void SendSMTPEmail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody)
        {
            try
            {
                SmtpClient client = new SmtpClient(strSmtpServer);
                client.Port = 25;
                client.UseDefaultCredentials = false;
                client.Credentials = new NetworkCredential(strFrom, strFromPass);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;

                //添加附件
                Attachment attachment = null;
                string pathFileName = @"F:\工作\问题规总.doc";
                attachment = new Attachment(pathFileName );

                MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
                message.Attachments.Add(attachment);
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml = true;
                client.Send(message);
            }
            catch
            {
            }
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值