2012-05-09 12 views
-6

添付ファイル付きのメールを一度に100人以上の人に送信しようとしています。添付ファイルで完璧に動作する非常に優れたソースコードを見つけましたが、一度に複数の人にメールを送信することはできません。このコードからより多くの人にメールを送信するには?

私の質問は次のとおりです。既存のコードを修正してその作業を手伝ってもらえますか?

プログラミング言語:のtargetAddressのパラメータでカンマでsplited

message.To.Add(new MailAddress("[email protected]"); 
+1

こんにちはたくは数10230920スパムボットこと:youreのだけ郵送し、それにサインアップすることにしたい人を郵送しない限り、Pを、その頼まれて多くの助けを期待してはいけませんここ数回:P – RhysW

+0

多くのこと...私は自分のコードと同様のコードで作業しますが、1つ以上の添付ファイルを送信することに問題があります。 – John

+0

ジョンのポイントは、あなたがすでに試したことを見せてくれました。それがうまくいかない理由を言うことができます... – RhysW

答えて

0

パスより多くの価値:私は、これはあなたが探しているものだと思います

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Net; 
using System.Net.Mail; 

namespace ConsoleApplication3 
{ 

    public class GmailAccount 
    { 
     public string Username; 
     public string Password; 
     public string DisplayName; 

     public string Address 
     { 
      get 
      { 
       return Username + "@gmail.com"; 
      } 
     } 

     private SmtpClient client; 

     public GmailAccount(string username, string password, string displayName = null) 
     { 
      Username = username; 
      Password = password; 
      DisplayName = displayName; 

      client = new SmtpClient 
      { 
       Host = "smtp.gmail.com", 
       Port = 587, 
       EnableSsl = true, 
       DeliveryMethod = SmtpDeliveryMethod.Network, 
       UseDefaultCredentials = false, 
       Credentials = new NetworkCredential(Address, password) 
      }; 
     } 

     public void SendMessage(string targetAddress, string subject, string body, params string[] files) 
     { 
      MailMessage message = new MailMessage(new MailAddress(Address, DisplayName), new MailAddress(targetAddress)) 
      { 
       Subject = subject, 
       Body = body 
      }; 

      foreach (string file in files) 
      { 
       Attachment attachment = new Attachment(file); 
       message.Attachments.Add(attachment); 
      } 

      client.Send(message); 
     } 
    } 

    class Program 
    { 
     static void Main(string[] args) 
     { 
      GmailAccount acc = new GmailAccount("username", "password", "Caption"); 
      acc.SendMessage("[email protected]", "Hello World!", "like in the title...", "C:\\temp.rar"); 
     } 
    } 
    } 
+0

回答を得るためにthnx私はそれを試してみる... – John

+3

* facepalm *彼のためにそれをするために他の人に頼るのではなく、自分自身を行うために新しい男を教える方法:P – RhysW

1

:ここではC#

コードですメッセージを送る。

複数の人にメールを送信するためのサンプルコード:

public bool SendEmail() 
{ 
    bool status = false; 

     try 
     { 
      //code to send email 
      this._mail = new MailMessage(); 

      this._mail.From = new MailAddress(this.From, this.DisplayName); 

      if (!string.IsNullOrEmpty(this.To)) 
      { 
       var distinctAddress = new List<string>(this.To.Split(',').Distinct()); 
       this.To = string.Empty; 

       foreach (string address in distinctAddress) // Loop through all strings 
       { 
        this.To += address + ","; // Append string to StringBuilder 
       } 
       this.To = this.To.TrimEnd(','); 
       this._mail.To.Add(this.To); 
      } 

      if (!string.IsNullOrEmpty(this.CC)) 
       this._mail.CC.Add(this.CC); 

      if (!string.IsNullOrEmpty(this.BCC)) 
       this._mail.Bcc.Add(this.BCC); 

      this._mail.Subject = this.Subject; 

      this._mail.IsBodyHtml = this.IsBodyHtml; 

      this._mail.Body = this.Body; 

      if (this.Priority == true) 
      { 
       this._mail.Priority = MailPriority.High; 
      } 

      this._mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; 

      if (this._attachments != null && this._attachments.Count > 0) 
      { 
       foreach (string file in this._attachments) 
       { 
        Attachment attachment = new Attachment(file); 
        this._mail.Attachments.Add(attachment); 
       } 
      } 

      this._smtpServer = new SmtpClient(this.EmailServer); 
      this._smtpServer.EnableSsl = this.EnableSsl; 
      this._smtpServer.Port = this.Port; 
      this._smtpServer.Credentials = new System.Net.NetworkCredential(this.UserId, this.Password); 

      if (String.IsNullOrEmpty(this.To) != true || string.IsNullOrEmpty(this.CC) != true || string.IsNullOrEmpty(this.BCC) != true) 
       this._smtpServer.Send(this._mail); 
      status = true; 
     } 
     catch (Exception ex) 
     { 
     } 
    return status; 
} 
+1

彼は、メールを送りたい人やループを繰り返している何百人もの人のリスト"[email protected]"は私がループ数とリスト番号の両方を選んでリストの最後に到達するまでの間に実行します。あなたを離れて、より役に立つようにあなたの答えに追加) – RhysW

+1

私は同意します。彼は質問に多くの努力をしなかったので、私は彼にすべてを与えたくなかった。 –

関連する問題