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

  • 相关阅读:
    sqlalchemy-数据目录集合整合
    算法-lowb三人组
    ipython ---matplotlib:绘图和可视化
    ipython --pandas
    ipython --之Numpy
    字符编码
    Markdown——入门使用
    python集合操作和内置方法
    python字典操作和内置方法
    python元祖操作和内置方法
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/3059353.html
Copyright © 2011-2022 走看看