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

  • 相关阅读:
    Command 命令模式
    Composite 组合模式
    Decorator 装饰器模式
    Abstract Factory 抽象工厂模式
    输入框测试重点:
    w​e​b​网​站​常​用​测​试​用​例
    性能测试常见分类
    Web 常用的测试方法
    em、rem和px的区别
    [if lt IE 9]等符号的含义
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/3059353.html
Copyright © 2011-2022 走看看