using System.Web.Mail to send email

简介: there are many demos for send a email with c sharp language .however,you will find that most of them will be failed because of SMTPServer.

there are many demos for send a email with c sharp language .however,you will find that most of them will be failed because of SMTPServer.Especially,authorization is required.

 

public   void  SendEMail()
        
{
            MailMessage mail 
= new MailMessage();
            mail.Priority 
= MailPriority.High;
            mail.From 
= "cccc@gmail.com";
            mail.To 
= "cccc@163.com";
            mail.Subject 
= "Send EMail System Demo";
            mail.Body 
= "Just for test.";
            mail.BodyEncoding 
= Encoding.UTF8;

            
// authorization
            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing"1);
            mail.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendemailaddress", mail.From);
            mail.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress", mail.From);
            mail.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpaccountname""cccc@163.com");
            mail.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendpassword""cccc");
            mail.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"1);
            mail.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpserver""smtp.163.com");

            SmtpMail.SmtpServer 
= "smtp.163.com";
            SmtpMail.Send(mail);
        }

        
#endregion

 

 

目录
相关文章
|
3月前
|
存储 Java 数据库
javax.security.auth.login.LoginException: Message stream modified (41)
`亲测可用,之前搜索了很多博客,啥样的都有,就是不介绍报错以及配置用处,根本不懂照抄那些配置是干啥的,稀里糊涂的按照博客搭完也跑不起来,因此记录这个。` `项目背景`:公司项目当前采用http协议+shiro+mysql的登录认证方式,而现在想支持ldap协议认证登录然后能够访问自己公司的项目网站。 `举例说明`:假设我们公司有自己的门户网站,现在我们收购了一家公司,他们数据库采用ldap存储用户数据,那么为了他们账户能登陆我们公司项目所以需要集成,而不是再把他们的账户重新在mysql再创建一遍,万一人家有1W个账户呢,不累死了且也不现实啊。
47 7
|
SQL 前端开发 Java
Web message book | JavaWeb
Web message book | JavaWeb
81 0
Web message book | JavaWeb
|
网络安全 开发工具