zoukankan      html  css  js  c++  java
  • C#发送邮件

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Mail;
    using System.Text;
    using System.Threading.Tasks;
    using ShopMall.Model;
    using System.Diagnostics;

    namespace ShopMall.Common
    {
    public class sendEmail
    {
    private readonly SmtpClient Client;

    public sendEmail(siteconfig site)
    {
    Client = new SmtpClient
    {
    Host = "smtp.qq.com",
    Port =25,
    DeliveryMethod = SmtpDeliveryMethod.Network
    };
    Client.UseDefaultCredentials = false;
    Client.Credentials = new NetworkCredential("1002275364@qq.com","xxxxxxxxxxxxx");
    }

    /// <summary>
    /// 发送邮件
    /// </summary>
    /// <param name="from"></param>
    /// <param name="to"></param>
    /// <param name="subject"></param>
    /// <param name="body"></param>
    /// <returns></returns>
    public bool SendMessage(string from, string to, string subject, string body)
    {
    MailMessage msg = null;
    bool isSent = false;
    using (msg = new MailMessage(from, to, subject, body))
    {
    try
    {
    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
    msg.BodyEncoding = System.Text.Encoding.UTF8;
    msg.IsBodyHtml = true;

    Client.Send(msg);
    isSent = true;
    }
    catch (Exception ex)
    {
    isSent = false;
    Trace.TraceError(ex.Message);
    }
    return isSent;
    }
    }
    }
    }

    在调用的时候提示mail from address must be same as authorization user,google后才知道 原来还需要邮箱开启smtp服务才行,于是乎(看下图)

    保存后,ok啦

  • 相关阅读:
    NetworkX-根据权重画图
    Matplotlib 画廊
    NetworkX-画图
    NetworkX-simple graph
    python+networkx
    AttributeError: 'module' object has no attribute 'X509_up_ref'
    python Flask post 数据 输出
    windows环境下批处理实现守护进程
    supervisor自启动
    支持高并发的IIS Web服务器常用设置
  • 原文地址:https://www.cnblogs.com/xiexingen/p/3900536.html
Copyright © 2011-2022 走看看