zoukankan      html  css  js  c++  java
  • SMTP发送邮件的简单实现

    public static bool Send(string sendTo, string subject, string body)
    {
    return Send(sendTo, subject, body, false);
    }

    public static bool Send(string sendTo, string subject, string body, bool isHTML)
    {
    bool result = false;
    IPHostEntry ipe = Dns.GetHostEntry(Dns.GetHostName());
    IPAddress ipa = ipe.AddressList[0];

    //本机的SMTP服务器

    SmtpClient client = new SmtpClient(ipa.ToString());
    string password = ConfigurationManager.AppSettings[ipa.ToString()];
    client.Credentials = new NetworkCredential("administrator", password);


    //
    // SmtpClient client = new SmtpClient("smtp.163.com");//邮件服务器
    //client.Credentials = new NetworkCredential("cccdddppp@163.com", "密码");


    MailMessage msg = new MailMessage("Manage@Tjy.net", sendTo);
    msg.SubjectEncoding = msg.BodyEncoding = Encoding.GetEncoding("gb2312");
    msg.IsBodyHtml = isHTML;
    msg.Subject = subject;
    msg.Body = body;
    // MailAddress from = new MailAddress("service@carhappy.com.cn");
    // MailAddressCollection to = new MailAddressCollection();
    try
    {
    client.Send(msg);
    result = true;
    }
    catch (Exception)
    {

    result = false;
    }
    return result;
    }

  • 相关阅读:
    设计模式
    TCP拥塞控制
    TCP 连接建立和断开,以及状态转换
    python unicode字符串
    python语法笔记(七)
    python语法笔记(六)
    python语法笔记(五)
    python语法笔记(四)
    python语法笔记(三)
    【密码学】公钥与私钥
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/3059353.html
Copyright © 2011-2022 走看看