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

  • 相关阅读:
    20150212-2015
    SM30维护视图添加按钮
    SAP保存操作记录CDHDR和CDPOS表
    20150123-慢慢
    20150124-轻轻
    维护 物料主数据 号码段
    ABAP DEMO-2018
    工具
    幽门螺杆菌资料收集
    MySQL 8 连接时出现 1251 和 2059 错误
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/3059353.html
Copyright © 2011-2022 走看看