发送电子邮件方法

/// <summary>
       /// 发送邮件
       /// </summary>
       /// <param name="sendAdress">发送邮件地址</param>
       /// <param name="receiveAdress">接收邮件地址,如有多个以,分隔</param>
       /// <param name="Title">邮件标题</param>
       /// <param name="Content">邮件内容</param>
       /// <param name="pwd">发件人密码</param>
       public static void SendMail(string sendAdress,string receiveAdress,string Title,string Content,string pwd) 
       {
           //取出所有的收件人地址
           string[] adressCollect = receiveAdress.Split(new Char[] { ',' });
           foreach (string item in adressCollect)
           {
               MailMessage msg = new MailMessage(sendAdress, item);
               //通过发送地址取出smtp地址
               string[] service = sendAdress.Split(new Char[] { '@', '.' });
               //组合smtp地址
               string smtpAdress = "smtp." + service[1] + ".com";
               SmtpClient smtpClient = new SmtpClient(smtpAdress);
               //指示通过网络发送电子邮件
               smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
               //身份验证
               smtpClient.Credentials = new NetworkCredential(sendAdress, pwd);
               //设置邮件标题和内容
               msg.Subject = Title;
               msg.Body = Content;
               //发送邮件
               try
               {
                   smtpClient.Send(msg);
               }
               catch (Exception e)
               {

                   throw e;
               }
           }
       }
posted @ 2012-04-16 16:33  行走的娃娃  阅读(341)  评论(0编辑  收藏  举报