• C#发送邮件可用代码


    public MailMessage Initial(string Address)
            {
                MailMessage m_Mail = new MailMessage();
                //发件人
                m_Mail.From = new MailAddress("******@126.com");
                //收件人
                m_Mail.To.Add(new MailAddress(Address));
                //主题
                m_Mail.Subject ="代理好久没验证了!!!";
                //内容
                m_Mail.Body = "赶紧重开一下吧!!!";
                //邮件主题和正文编码格式
                m_Mail.SubjectEncoding = System.Text.Encoding.UTF8;
                m_Mail.BodyEncoding = System.Text.Encoding.UTF8;
                //邮件正文是Html编码
                m_Mail.IsBodyHtml = true;
                //优先级
                m_Mail.Priority = System.Net.Mail.MailPriority.High;
                //添加附件,可以添加多个
                //m_Mail.Attachments.Add(new Attachment("c:\\1.txt"));
                //密件抄送收件人
                m_Mail.Bcc.Add(Address);
                //抄送收件人
                m_Mail.CC.Add(Address);
    
                return m_Mail;
            }a
    
    
    
                SmtpClient client = new SmtpClient();
                //这个地方的用户名你可以用split从发送人中截取
                client.Credentials = new System.Net.NetworkCredential("****", 密码);
                client.Port = 25;
                client.Host = "smtp.126.com";
                try
                {
                    client.Send(Initial("******@qq.com"));
                    //ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script>alert('发送成功!')</script>");
                    SuccMsg.Add("发送邮件成功!" + "******@qq.com");
                    return true;
                }
                catch (System.Net.Mail.SmtpException ex)
                {
                    SuccMsg.Add("发送邮件失败!" + "*****@qq.com");
                    return false;
                }    
  • 相关阅读:
    哈夫曼
    P1631序列合并
    PAT Mice and Rice
    ybt 1356 计算(calc)
    P2947 Look Up S
    electron主进程与渲染进程的通信方式
    自定义BufferedReader
    小程序云数据库查询数据用在其它任意地方(完美解决)
    html+js实现微信跳转遮罩层
    Java创建属于自己的二维码(完整版)
  • 原文地址:https://www.cnblogs.com/jhabb/p/2854501.html
Copyright © 2020-2023  润新知