c#发送邮件

原创 2007年09月27日 17:36:00
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#发送邮件

C#发送邮件和fax的代码

  • 2012-11-21 12:03
  • 51KB
  • 下载

C#发送邮件三种方法,Localhost,SMTP,SSL-SMTP

http://yeak2001.iteye.com/blog/859770 (转)C#发送邮件三种方法,Localhost,SMTP,SSL-SMTP 通过.Net FrameWork 2.0下...

C#发送邮件三种方法,Localhost,SMTP,SSL-SMTP

(转)C#发送邮件三种方法,Localhost,SMTP,SSL-SMTP 通过.Net FrameWork 2.0下提供的“System.Net.Mail”可以轻松的实现,本文列举了3种途径来发送...

C#发送邮件实例

  • 2016-06-25 14:39
  • 75KB
  • 下载

Jmail发送邮件C#.rar

  • 2009-11-09 10:46
  • 1.49MB
  • 下载

c# 发送邮件、附件

WinForm窗体代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using Sy...

c#发送邮件

  • 2013-01-18 17:27
  • 45KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)