c#发送邮件

private void sendMail()
        {
            string s_from = "aaa@htdchina.com";
            string s_to = "bbb@htdchina.com";
            string pwd = "pwd";
            string s_body = "测试邮件";
            s_body = s_body.Replace("/r/n", "<br/>");
            s_body = s_body.Replace("/n", "<br/>");
            s_body = s_body.Replace(" ", "&nbsp");
            int i = s_from.IndexOf("@");
            string username = s_from.Substring(0, i);
            MailAddress from = new MailAddress(s_from);
            MailAddress to = new MailAddress(s_to);
            MailMessage mailobj = new MailMessage(from, to);
            mailobj.Subject = "my title";
            mailobj.Body = s_body;
            mailobj.IsBodyHtml = true;
            mailobj.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
            mailobj.Priority = MailPriority.High;
          
            mailobj.Attachments.Add(new Attachment("c://test.jpg"));
          
            SmtpClient smtp = new SmtpClient("mail.htdchina.com");
            // smtp.Host = "smtp.163.com";
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential(username, pwd);
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

            try
            {
                smtp.Send(mailobj);
                MessageBox.Show("success");

            }
            catch
            {
                MessageBox.Show("error");
            }
        }
阅读更多
文章标签: c# string 测试 c
上一篇获取网页内容
下一篇资料收集
想对作者说点什么? 我来说一句

C#发送邮件

2018年01月04日 49KB 下载

C#发送邮件 CS版

2018年03月02日 28KB 下载

C# Winform 发送邮件

2010年04月21日 37KB 下载

没有更多推荐了,返回首页

关闭
关闭