• 2017-6-10 发送邮件


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <br /><br />
             接收者:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
            邮件标题:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br />
            邮件内容:<asp:TextBox ID="TextBox3" TextMode="MultiLine" runat="server"></asp:TextBox><br /><br />
            <asp:Button ID="Button1" runat="server" Text="发送" />
        </div>
        </form>
    </body>
    </html>
    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;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Click += Button1_Click;
        }
    
        void Button1_Click(object sender, EventArgs e)
        {
            string to = TextBox1.Text;
            string title = TextBox2.Text;
            string content = TextBox3.Text;
    
            //发送邮件
            //创建邮箱服务器对象
            SmtpClient smtp = new SmtpClient("smtp.qq.com");
            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;
            //发送者是谁
            MailAddress fr=new MailAddress("757113394@qq.com");
            //接收者是谁
            MailAddress t = new MailAddress(to);
            MailAddressCollection clist = new MailAddressCollection();
            clist.Add(t);
            //发送的邮件对象
            MailMessage mail = new MailMessage(fr,t);
           
            //给邮件对象标题属性赋值
            mail.Subject = title;
            //给邮件对象内容属性赋值
            mail.Body = content;
            //创建资格证书对象
            NetworkCredential cred = new NetworkCredential("757113394", "rykemipvuzbvbcbd");
    
            //设置资格证书
            smtp.Credentials = cred;
            //发送
    
            smtp.Send(mail);
        }
    
        
    }
  • 相关阅读:
    RabbitMQ安装与配置
    在Web项目中使用shiro
    solr整合spring
    mycat
    SpringSession管理
    Nginx安装与配置(Nginx服务器和Tomcat服务器是不同的服务器)
    dubbo负载均衡与服务降级以及Zookeeper认证
    小笔记
    SpringMVC路径转发与重定向
    java-同步控制及不可变设置(只读访问)
  • 原文地址:https://www.cnblogs.com/zhengqian/p/6992613.html
Copyright © 2020-2023  润新知