记录一个发邮件的cs文件

C# 邮件发送接口实现
ExpandedBlockStart.gifContractedBlock.gif    /**//* ---------------------------------
InBlock.gif     *     E-mail 发送接口
InBlock.gif     *     调用示例 
InBlock.gif     * ---------------------------------
ExpandedBlockEnd.gif     
*/
 
None.gif    
public class webMail
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
-- declare the variables --#region -- declare the variables --
InBlock.gif        
private string _sender = "";
InBlock.gif        
private string _account = "";
InBlock.gif        
private string _password = "";
InBlock.gif        
private string _server = "";
InBlock.gif        
private string _subject = "";
InBlock.gif        
private string _body = "";
InBlock.gif        
private string _recv = "";
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
-- declare the interface --#region -- declare the interface --
InBlock.gif        
public string sender
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _sender 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public string sendAccount
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _account 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public string sendPassword
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _password 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public string sendServer
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _server 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public string sendSubject
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _subject 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public string sendBody
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _body 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public string sendRecv
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _recv 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
string sendMail()#region string sendMail()
InBlock.gif        
public string sendMail()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MailMessage mailMessage 
= new MailMessage();
InBlock.gif
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate""1"); 
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendusername", _account); 
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendpassword", _password); 
InBlock.gif                mailMessage.From 
= _sender;
InBlock.gif                mailMessage.To 
= _recv;
InBlock.gif                mailMessage.Subject 
= _subject;
InBlock.gif                mailMessage.Body 
= _body;
InBlock.gif
InBlock.gif                SmtpMail.SmtpServer 
= _server;
InBlock.gif                SmtpMail.Send(mailMessage);
InBlock.gif
InBlock.gif                
return "1";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return ex.Message.ToString();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
string testSend(string sender,string subject,string body,string recv)#region string testSend(string sender,string subject,string body,string recv)
InBlock.gif        
public string testSend(string sender,string subject,string body,string recv)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MailMessage mailMessage 
= new MailMessage();
InBlock.gif
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate""1"); 
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendusername""kefu@huabaoTrust.com"); 
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendpassword""123456"); 
InBlock.gif                mailMessage.From 
= sender;
InBlock.gif                mailMessage.To 
= recv;
InBlock.gif                mailMessage.Subject 
= subject;
InBlock.gif                mailMessage.Body 
= body;
InBlock.gif
InBlock.gif                SmtpMail.SmtpServer 
= "www.huabaotrust.com";
InBlock.gif                SmtpMail.Send(mailMessage);
InBlock.gif
InBlock.gif                
return "1";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return ex.Message.ToString();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
string sendMail(string sender,string subject,string body,string recv)#region string sendMail(string sender,string subject,string body,string recv)
InBlock.gif        
public string sendMail(string sender,string subject,string body,string recv)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MailMessage mailMessage 
= new MailMessage();
InBlock.gif
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate""1"); 
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendusername", _account); 
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendpassword", _password); 
InBlock.gif                mailMessage.From 
= sender;
InBlock.gif                mailMessage.To 
= recv;
InBlock.gif                mailMessage.Subject 
= subject;
InBlock.gif                mailMessage.Body 
= body;
InBlock.gif
InBlock.gif                SmtpMail.SmtpServer 
= _server;
InBlock.gif                SmtpMail.Send(mailMessage);
InBlock.gif
InBlock.gif                
return "1";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return ex.Message.ToString();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
string sendMail(string sender,string subject,string body,string recv,string server,string account,string password)#region string sendMail(string sender,string subject,string body,string recv,string server,string account,string password)
InBlock.gif        
public string sendMail(string sender,string subject,string body,string recv,string server,string account,string password)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MailMessage mailMessage 
= new MailMessage();
InBlock.gif
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate""1"); 
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendusername", account); 
InBlock.gif                mailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendpassword", password); 
InBlock.gif                mailMessage.From 
= sender;
InBlock.gif                mailMessage.To 
= recv;
InBlock.gif                mailMessage.Subject 
= subject;
InBlock.gif                mailMessage.Body 
= body;
InBlock.gif
InBlock.gif                SmtpMail.SmtpServer 
= server;
InBlock.gif                SmtpMail.Send(mailMessage);
InBlock.gif
InBlock.gif                
return "1";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return ex.Message.ToString();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedBlockEnd.gif    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值