惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
博客园 - 司徒正美
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
博客园 - 聂微东
M
MIT News - Artificial intelligence
博客园_首页
Jina AI
Jina AI
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Vercel News
Vercel News
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
B
Blog
Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 魏绰

冲销会计凭证:FBRP与FB08的区别 xk01创建供应商保存的时候,提示错误“科目800001已经存在” SAP如何使用关于序列号的表 解决:“凭证编号 ******** 已分配!”的错误 Payment Terms 收付款条件和分期付款设置 bw R/3端配置 (转) SAP WM 层面仓位调整 在ABAP中用事务更新数据(转) ABAP设置JOB 专家例程 SMARTFORM 点击打印后,将打印次数或者是最后的打印时间添加到数据表中 SMARTFORMS 分页函数显示 '*" [转]SAP ABAP中使用Read_Text函数读取项目文本的方法 ABAP生成随机数 BW知识点总结及面试要点(转) se93 为自建表分配维护事物码 F4搜索帮助 F4IF_INT_TABLE_VALUE_REQUEST SAP系统中设定流水号 SAP 调用外部程序 .转
asp.net 发送邮件
魏绰 · 2012-04-17 · via 博客园 - 魏绰

1.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
using LTP.Accounts.Bus;
using System.IO;
using System.Data.SqlClient;
using System.Text;
using System.Drawing;
using System.Web.Mail;
using System.Text.RegularExpressions;

namespace Studeny.Common
{
   public  class SendMail
    {

        public static bool Send(string strTo, string strBody, string strSubject, string strForm, string strUserName, string strPwd, string strServer)
        {

            MailMessage mm = new MailMessage();//创建邮件对象

            mm.From = strForm;//获取发件人的电子邮箱(多人用","分隔)

            mm.To = strTo;//获取收件人的电子邮箱

            mm.Subject = strSubject;//邮件标题

            mm.Body = strBody;//邮件正文

            mm.BodyFormat = System.Web.Mail.MailFormat.Html;//格式

            mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");//基本权限

            mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strUserName);//自己的邮箱名

            mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", strPwd);//自己的邮箱密码

            SmtpMail.SmtpServer = strServer;//服务器地址

            try
            {

                SmtpMail.Send(mm);

                return true;

            }

            catch
            {

                return false;

            }

        }

        public static bool isEmail(string inputEmail)
        {
            string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            Regex re = new Regex(strRegex);
            if (re.IsMatch(inputEmail))
            {
                return true;
            }
            else
            {
                return false;
            }
        }  
    }
}

2.调用

  if (Common.SendMail.Send(lblUserName.Text.Trim(), "内容", "我要听课", ConfigurationManager.AppSettings.Get("WebEmail"), ConfigurationManager.AppSettings.Get("WebEmailUserName"), ConfigurationManager.AppSettings.Get("WebEmailpwd"), ConfigurationManager.AppSettings.Get("WebEmailServer")))
                            {
                                Common.MessageBox.Show(this.Page, "恭喜您!邮件发送成功");
                            }
                            else
                            {
                                Common.MessageBox.Show(this.Page, "SORRY!邮件发送失败");
                            }
                            return;

3.web.config

 <appSettings>

  <add key="WebEmailServer" value="smtp.163.com"/>
  <!-- 发件邮箱-->
  <add key="WebEmail" value="www@163.com"/>
  <!-- 发件邮箱用户名-->
  <add key="WebEmailUserName" value="www"/>
  <!-- 发件邮箱密码-->
  <add key="WebEmailpwd" value="www"/>

</appSettings>