2017-05-24 10 views
0

Windowsのリストボックスを使用してバルクメールを送信すると問題が発生します。バルクメールを送信しようとすると送信が失敗します。私はチェックしてチェックしたコードが間違っているか分からない。何が間違っているのかわからない。コードを実行して送信するとエラーが発生します。

void SendMail1(string from,string to,string subject,string message,string host,int port,string un,string pw) 
    { 
     MailMessage tm = new MailMessage(); 
     tm.From = new MailAddress(from); 
     tm.To.Add(new MailAddress(to)); 
     tm.Subject = subject; 
     tm.Body = message; 
     tm.IsBodyHtml = true; 
     tm.Priority = MailPriority.Normal; 
     tm.SubjectEncoding = Encoding.UTF8; 
     var smtp = new SmtpClient(); 
     { 
      smtp.Host = host; 
      smtp.Port = port; 
      smtp.EnableSsl = true; 
      smtp.UseDefaultCredentials = true; 
      smtp.DeliveryMethod = SmtpDeliveryMethod.Network;    
      //default credentials 
      smtp.Credentials = new NetworkCredential(un,pw); 
     } 
     smtp.Send(tm); 
     MetroFramework.MetroMessageBox.Show(this, "Bulk Mail Successfully Sent.....", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); 
    } 


    private void btnSendEmail2_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      if (string.IsNullOrEmpty(txtSubject2.Text) || string.IsNullOrEmpty(txtMessage2.Text) || string.IsNullOrEmpty(txtFrom2.Text) || string.IsNullOrEmpty(txtEmailAddress2.Text) || string.IsNullOrEmpty(txtPassword2.Text) || string.IsNullOrEmpty(txtAttachment2.Text)) 
      { 
       MetroFramework.MetroMessageBox.Show(this, "One Or More Fields Empty..Please Check To See Which Fields Are Empty,Before Sending Mails...", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
      } 
      else 
      { 
       //send mails here 
       foreach(string i in lstEmails.Items) 
       { 
        if (i.Trim() != string.Empty) 
        { 
         //declare all fields 
         DataTable dt = new DataTable("tblEmails"); 
         dt.Columns.Add("Email", typeof(string)); 
         dt.Rows.Add(i.ToString()); 
         string _from = txtFrom2.Text.Trim(); 
         string _subject = txtSubject2.Text.Trim(); 
         string _message = txtMessage2.Text.Trim(); 
         string _host = Convert.ToString(ddlProvider2.SelectedItem); 
         int _port = 587; 
         string _un = txtEmailAddress2.Text.Trim(); 
         string _pw = txtPassword2.Text.Trim(); 
         Parallel.ForEach(dt.AsEnumerable(), x => 
         { 
          SendMail1(_from, x["Email"].ToString(), _subject,_message 
           , _host, _port, _un, _pw); 
         }); 

         // MetroFramework.MetroMessageBox.Show(this, i + "\n", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); 
        } 
        else 
        { 
         MetroFramework.MetroMessageBox.Show(this, "Please Load Some Emails To Send Mail Message...", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
        } 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK); 
     } 
    } 
+2

エラーが発生するのは、どの行ですか? SendMail1は動作し、SendMail2は動作しませんか?エラーメッセージとは何ですか? – LarsTech

+0

これは、エラーsmtp.Send(tm)を示す行です。 –

+0

これはエラーです。メールの送信に失敗しました。 –

答えて

0

あなたは電子メールを一括送信しようとしている。これが「時には」動作している場合は、送信レートが管理者が設定したしきい値を超えると、SMTPサーバーがメッセージを拒否している可能性があります。このような場合は、管理者がアプリケーションに合わせてポリシーを変更しない限り、できることはあまりありません。または、別のSMTPサービスが必要です(Amazonには、あなたのようなバルクメールアプリケーション用のものしかありません)。

+0

wow didnt sir ... plsもっと知るにはリンクを教えてくださいそれ... –

+0

これを試してみてくださいhttp://cybercity.nyc/blog/bulk-email-or-spam-how-to-send-email-blasts-and-newsletters-and-avoid-blacklisting/このhttps:/ /aws.amazon.com/ses/faqs/およびhttp://support.proofpointessentials.com/index.php?/Knowledgebase/Article/View/74/4/bulk-email-limitations-explained –

+0

これは次の例です。送信制限。 –

関連する問題