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

推荐订阅源

Google Online Security Blog
Google Online Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
Cisco Talos Blog
Cisco Talos Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Scott Helme
Scott Helme
Project Zero
Project Zero
E
Exploit-DB.com RSS Feed
S
Secure Thoughts
K
Kaspersky official blog
L
Lohrmann on Cybersecurity
NISL@THU
NISL@THU
WordPress大学
WordPress大学
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LINUX DO - 热门话题
小众软件
小众软件
P
Privacy & Cybersecurity Law Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
Hacker News: Ask HN
Hacker News: Ask HN
AWS News Blog
AWS News Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hacker News: Front Page
F
Full Disclosure
Latest news
Latest news
Schneier on Security
Schneier on Security
The Hacker News
The Hacker News
T
Troy Hunt's Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Jina AI
Jina AI
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
TaoSecurity Blog
TaoSecurity Blog
G
GRAHAM CLULEY
Forbes - Security
Forbes - Security
V
V2EX - 技术
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Vulnerabilities – Threatpost
C
Cyber Attacks, Cyber Crime and Cyber Security
MongoDB | Blog
MongoDB | Blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
P
Privacy International News Feed
C
Check Point Blog
N
News and Events Feed by Topic

博客园 - 魏绰

冲销会计凭证: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>