.Net 邮件发送的类,在程序中直接调用就可以了
2008-04-03 23:09
441 查看
.Net 邮件发送的类,在程序中直接调用就可以了,利用别人提供的smtp,就可以发Email了。
using System;
using System.Web.Mail;
namespace ZhongRongBai
{
///
/// SystemMail 的摘要说明。
///
public class SystemMail
{
private string _adminEmail;
//private string _smtpServer = "localhost";
private string _smtpServer;
private string _password;
private string _userName;
public SystemMail()
{
}
public string AdminEmail
{
get{return _adminEmail;}
set{_adminEmail = value;}
}
public string SmtpServer
{
get{return _smtpServer;}
set{_smtpServer = value;}
}
public string Password
{
get{return _password;}
set{_password = value;}
}
public string UserName
{
get{return _userName;}
set{_userName = value;}
}
public bool Send(string to, string from, string subject, string message)
{
try
{
MailMessage em = new MailMessage();
em.To = to;
em.From = from;
em.Subject = subject;
em.Body = message;
em.BodyFormat=MailFormat.Html;
em.Headers.Add( "Reply-To", "sales@qqview.com" );
//em.Bcc= to;
//Found out how to send authenticated email via System.Web.Mail at http://SystemWebMail.com (fact 3.8)
if(this.UserName != null && this.Password != null)
{
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.UserName); //set your username here
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.Password); //set your password here
}
SmtpMail.SmtpServer = this.SmtpServer;
SmtpMail.Send(em);
return true;
}
catch
{
return false;
}
}
}
}
using System;
using System.Web.Mail;
namespace ZhongRongBai
{
///
/// SystemMail 的摘要说明。
///
public class SystemMail
{
private string _adminEmail;
//private string _smtpServer = "localhost";
private string _smtpServer;
private string _password;
private string _userName;
public SystemMail()
{
}
public string AdminEmail
{
get{return _adminEmail;}
set{_adminEmail = value;}
}
public string SmtpServer
{
get{return _smtpServer;}
set{_smtpServer = value;}
}
public string Password
{
get{return _password;}
set{_password = value;}
}
public string UserName
{
get{return _userName;}
set{_userName = value;}
}
public bool Send(string to, string from, string subject, string message)
{
try
{
MailMessage em = new MailMessage();
em.To = to;
em.From = from;
em.Subject = subject;
em.Body = message;
em.BodyFormat=MailFormat.Html;
em.Headers.Add( "Reply-To", "sales@qqview.com" );
//em.Bcc= to;
//Found out how to send authenticated email via System.Web.Mail at http://SystemWebMail.com (fact 3.8)
if(this.UserName != null && this.Password != null)
{
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.UserName); //set your username here
em.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.Password); //set your password here
}
SmtpMail.SmtpServer = this.SmtpServer;
SmtpMail.Send(em);
return true;
}
catch
{
return false;
}
}
}
}
相关文章推荐
- 自己写的一个mail发送组件,可以直接在程序中调用。
- 使用.net程序发送邮件代码
- Android 调用系统邮件程序发送邮件
- 在VC中调用默认的电子邮件程序发送邮件
- PHP调用mail( )函数直接发送邮件
- 如题,既然直接对一个实例发送方法名就可以调用这个方法,那为什么还要使用performSelector:去调呢?两者u有啥区别
- .Net语言 APP开发平台——Smobiler学习日志:如何在手机中调用邮件发送接口
- 邮件发送.net 的实现 vs2008 可以加附件
- Android不调用第三方程序发送邮件
- 在VC中调用默认的电子邮件程序发送邮件
- python写的调用ms sqlserver数据并发送邮件的小程序
- 在VC中调用默认的电子邮件程序发送邮件
- .Net语言 APP开发平台——Smobiler学习日志:如何在手机中调用邮件发送接口
- 邮件发送程序(可以同时发给多个地址、可以带附件)
- VC++ 使用ShellExecute函数调用邮箱客户端发送邮件(可以带附件)
- JAVA程序调用javax.mail发送邮件
- VC 中调用默认邮件发送程序(Outlook)发送 指定附件的email
- vbs-获取公网IP调用邮件控件实现邮件的自动发送到指定邮箱-可直接使用复制使用
- PHP MAIL DEMO(程序代码直接发送邮件)
- .Net调用QQ邮箱发送邮件