zoukankan      html  css  js  c++  java
  • .net发送邮件

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net;
    using System.Net.Mail;//引用此命名空间
    using System.Text;
    public partial class Send : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //发送者邮件地址 
            string host = "ceshiyong_xu@163.com";
            //发送者邮件密码   
            string pwd = "ceshiyong";
            //接受者邮箱地址 
            string reciver = "ceshizhuanyong_xu@163.com";
            //SMTP服务器的主机名 
            string domainhost = "smtp.163.com";
            //邮件标题 
            string subject = "XXX邮件测试";
            //邮件发送的主题内容  
            string body = "这是邮件发送的主题";
            //调用方法,发送邮件
            if (SendEmail(host, pwd, reciver, domainhost, subject, body))
            {
                Response.Write("<script>alert('发送成功!')</script>");
            }
        }
    
        /// <summary> /// 发送邮件,返回true表示发送成功/// </summary>  
        /// /// <param name="a">发件人邮箱地址;发件人用户名</param>   
        /// /// <param name="b">密码</param>   
        /// /// <param name="c">接受者邮箱地址</param>   
        /// /// <param name="host">SMTP服务器的主机名</param> 
        /// /// <param name="sub">邮件主题行</param>     
        /// /// <param name="body">邮件主体正文</param> 
        public bool SendEmail(string a, string b, string c, string host, string sub, string body)
        {
            System.Net.Mail.SmtpClient client = new SmtpClient();
            client.Host = host;
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(a, b);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            try
            {
                System.Net.Mail.MailMessage message = new MailMessage(a, c);
                message.Subject = sub;
                message.Body = body;
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml = true;
                client.Send(message);
                return true;
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "')</script>");
    
                return false;
            }
    
        }
    
    }
    View Code
  • 相关阅读:
    kubespray 容器存储设备 -- rook ceph
    RBAC 基于权限的访问控制 serviceaccount -- clusterRole clusterRoleBinding
    Kubernetes 1.10.4 镜像 版本
    rook 入门理解
    coredns CrashLoopBackOff 报错
    kubespray -- 快速部署高可用k8s集群 + 扩容节点 scale.yaml
    nginx反向代理 强制https请求 + 非root用户起80,443端口
    nginx rewrite flag
    CentOS7下双网卡iptables端口转发规则
    给php安装openssl扩展
  • 原文地址:https://www.cnblogs.com/xushining/p/3208161.html
Copyright © 2011-2022 走看看