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>");
            }
            
        }
    }

  • 相关阅读:
    算法沉思录之算法的结构
    OSSpinLockLock加锁机制,保证线程安全并且性能高
    iOS 开源库系列 Aspects核心源码分析---面向切面编程之疯狂的 Aspects
    代码阅读沉思录:代码的灵、肉与骨
    iOS AOP框架Aspects实现原理
    最近还是太浮躁了,一周阅读一个开源库是值得的
    performSelector 多参调用的实现方案
    oc消息转发:forwardInvocation、签名、参量个数、SEL 相关测试
    isa class superclass metaclass
    ARC与Toll-Free Bridging
  • 原文地址:https://www.cnblogs.com/yzenet/p/2371271.html
Copyright © 2011-2022 走看看