zoukankan      html  css  js  c++  java
  • 发送单个邮件

    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Text.RegularExpressions;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public bool SendNetMail(string mailFrom, string mailTo, string mailPassWord,
            string Server_Address, int Server_port)
        {
           string mailSubject = "imyasgs";//主题
           string mailBody = "imqsgsgs"; //内容
            //创建邮件
            //参数说明:
            //mailFrom :发送邮件地址
            //mailTo:接收邮件地址
            //mailPassWord:发送邮件的邮箱密码
            //mailSubject:邮件主题
            //mailBody:邮件内容
            //mailfilePath:邮件附件的路径集合,主要考虑到有时会发送多个附件的情况。
            //Server_Address:Smtp服务器地址
            //Server_port服务器端口

            System.Net.Mail.MailMessage newMail = new System.Net.Mail.MailMessage(mailFrom, mailTo, mailSubject, mailBody);
            newMail.IsBodyHtml = true;
            newMail.Priority = System.Net.Mail.MailPriority.Normal;//邮件发送优先级高

            //发送邮件
            string[] mailSmtp = Regex.Split(mailFrom, "@", RegexOptions.IgnoreCase);
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(mailSmtp[1].Insert(0, Server_Address),

    Server_port);
            client.Credentials = new System.Net.NetworkCredential(mailSmtp[0], mailPassWord);
            try
            {
                client.Send(newMail);
                return true;
            }
            catch
            {
                return false;

            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            ////读出数据库的发送邮件

            //string fa;
            //string mi;
            ////fff

            //foreach(DataRow dr in )
            //{
            //  bool  33=  fdf

            //      if(bool)
            //      {
                  
            //      }
            //}
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            if (SendNetMail("x@163.com", "y@163.com", "aaa123456", "SMTP.", 25))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "<script>alert('发送成功')</script>");

            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "<script>alert('发送成功')</script>");
            }
            
        }
    }

  • 相关阅读:
    Python爬虫基础——re模块的提取、匹配和替换
    Python爬虫基础——正则表达式
    Python爬虫基础——HTML、CSS、JavaScript、JQuery网页前端技术
    Python——面向对象(类)的基础疑难点
    简单易懂的ftp脚本自动登录教程
    如何完成述职报告或年终总结PPT
    nmon脚本——对Linux服务器的监控
    记——第一次服务器被挖矿
    vsftpd超实用技巧详解
    MySQL、Oracle、SqlServer的区别
  • 原文地址:https://www.cnblogs.com/yzenet/p/2371271.html
Copyright © 2011-2022 走看看