zoukankan      html  css  js  c++  java
  • mail数组

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


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

                        
    else
                        
    {
                            mail.Available 
    = false;
                       
                        }
       
                    mails.Add(mail);
                }

            }

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


            }

    //邮件发送方法
            public void RecommendSend(mailData mail)
            
    {
                
    try
                
    {
                    System.Net.Mail.MailMessage message 
    = new System.Net.Mail.MailMessage(
                        EmailFrom, mail.ToEmail, mail.Subject, mail.Content);
                    message.BodyEncoding 
    = System.Text.Encoding.UTF8;

                    System.Net.Mail.SmtpClient client 
    = new System.Net.Mail.SmtpClient(EmailHostName); //mail.itingwang.com邮件服务器
                    client.Credentials = new System.Net.NetworkCredential(EmailUserName, EmailPassword);//"servermgr@itingwang.com", ".itisservermgr"
                    client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;//邮件通过网络发送到smtp服务器
                    client.Send(message);
                    mail.sendstatus 
    = 1;
                }

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

                saveMail(mail);
            }

  • 相关阅读:
    搭建微信公众号,获取用户公开信息
    搭建ES搜索引擎,实时导入mysql数据进行查询
    切换linux的shell
    隐藏CMD窗口,使程序在后台执行
    通过ssh远程查看java版本与在客户端查看不一致
    项目升级tomcat,修复漏洞
    springboot重定向后,https变成http
    【数论】【Polya定理】【枚举约数】【欧拉函数】【Java】poj2154 Color
    【数论】【Polya定理】poj1286 Necklace of Beads
    【置换群】poj3270 Cow Sorting
  • 原文地址:https://www.cnblogs.com/shengel/p/1367839.html
Copyright © 2011-2022 走看看