mail数组

///建立   。多个邮件地址又“,”,“;”隔开 
None.gifprotected List<mailData> BuildMails()
ExpandedBlockStart.gifContractedBlock.gif    
{
InBlock.gif        List
<mailData> mails = new List<mailData>();   //mailData是一个email的实体类。
InBlock.gif
        CEmail email = new CEmail();
InBlock.gif        
string[] temps = this.TBtoemail.Text.Split(','';');
InBlock.gif        
string configStr = ConfigurationManager.AppSettings["recommendSubject"].ToString(); //邮件主题是配置文件配置的。
InBlock.gif

InBlock.gif
InBlock.gif        
for (int i = 0; i < temps.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
InBlock.gif            
//实例化具体mail实例
InBlock.gif
            if (!string.IsNullOrEmpty(temps[i].Trim()))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
InBlock.gif                mailData mail 
= new mailData();
InBlock.gif               
InBlock.gif                
//如果地址中有字符
InBlock.gif
          mail.Subject = string.Format(configStr, this.TBfriendname.Text, this.TBfromEmail.Text);
InBlock.gif                    mail.Encode 
= string.Empty;
InBlock.gif                    mail.SendTime 
= System.DateTime.Now;
InBlock.gif                    mail.UserName 
= this.TBfriendname.Text;
InBlock.gif                    mail.ApplicationName 
= "0";//0为好友推荐
InBlock.gif
                    mail.SendTime = DateTime.Now;
InBlock.gif                    mail.Content 
= this.content.Value;
InBlock.gif                    mail.FromMail 
= this.TBfromEmail.Text;
InBlock.gif                    mail.IPOuter 
= Context.Request.UserHostAddress;
InBlock.gif                    
InBlock.gif                    mail.ToEmail 
= temps[i];
InBlock.gif                    
if (CEmail.validatEmail(temps[i].Trim()))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
InBlock.gif                        mail.Available 
= true;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
InBlock.gif                        mail.Available 
= false;
InBlock.gif                   
ExpandedSubBlockEnd.gif                    }
   
InBlock.gif                mails.Add(mail);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
return mails;
ExpandedBlockEnd.gif    }
2:具体的发送代码None.gif//多封邮件。参数是list类型。  
None.gif
public void RecommendSend(List<mailData> mails)
ExpandedBlockStart.gifContractedBlock.gif        
{
InBlock.gif            
foreach (mailData mail in mails)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
InBlock.gif                
if (mail.Available)
InBlock.gif                    RecommendSend(mail);
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedBlockEnd.gif        }

None.gif
//邮件发送方法
None.gif
        public void RecommendSend(mailData mail)
ExpandedBlockStart.gifContractedBlock.gif        
{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
InBlock.gif                System.Net.Mail.MailMessage message 
= new System.Net.Mail.MailMessage(
InBlock.gif                    EmailFrom, mail.ToEmail, mail.Subject, mail.Content);
InBlock.gif                message.BodyEncoding 
= System.Text.Encoding.UTF8;
InBlock.gif
InBlock.gif                System.Net.Mail.SmtpClient client 
= new System.Net.Mail.SmtpClient(EmailHostName); //mail.itingwang.com邮件服务器
InBlock.gif
                client.Credentials = new System.Net.NetworkCredential(EmailUserName, EmailPassword);//"servermgr@itingwang.com", ".itisservermgr"
InBlock.gif
                client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;//邮件通过网络发送到smtp服务器
InBlock.gif
                client.Send(message);
InBlock.gif                mail.sendstatus 
= 1;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
InBlock.gif                mail.sendstatus 
= 0;  //sendstatus为0,sendstatus = -1; 邮件发送失败
InBlock.gif
                mail.ErrorMsg = ex.Message;
InBlock.gif                ApplicationLog.WriteError(ex.Message);
ExpandedSubBlockEnd.gif            }

InBlock.gif            saveMail(mail);
ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/shengel/archive/2009/01/04/1367839.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值