2013-12-11 36 views
-1

我們正面臨着一個VB.net的問題,它可以自動將電子郵件以文本文件附件發送到多個電子郵件地址。 奇怪的部分是,如果我們發送郵件給2人,然後第一個人收到電子郵件,但不是第二個。 如果我們添加三個電子郵件地址,那麼電子郵件會收到前兩個電子郵件地址,但收到第三個電子郵件地址。在添加更多電子郵件地址時,它會繼續這種方式。 另外,在第二次執行該腳本時,電子郵件會發送給所有收件人。確切地說,所有收件人只能在交替執行腳本時收到電子郵件。 這是否與郵件服務器等花費的時間有關? 終於我們做了這樣的工作,就是運行最後一個電子郵件地址的send email命令兩次。我知道這不是一個永久的解決方案。 任何幫助是高度讚賞。 在此先感謝。發送多封電子郵件失敗的最後一個電子郵件地址

public void Main() 
    { 
     SmtpClient client = new SmtpClient("1.1.1.1", 25); 

     client.DeliveryMethod = SmtpDeliveryMethod.Network; 

     client.Credentials = new NetworkCredential("support", "support"); 

     MailMessage EM1= new MailMessage("[email protected]", "[email protected] ", 
      "This is my subject" + " " + " ", "Hello,"); 

     EM1.Attachments.Add(new Attachment(@"F:\WebData\TxtFiles\1.txt")); 
     client.Send(EM1); 

     Dts.TaskResult = (int)ScriptResults.Success; 


     MailMessage EM2 = new MailMessage("[email protected]", "[email protected]", 
      "This is my subject" + " " + " ", "Hello,"); 

     EM2.Attachments.Add(new Attachment(@"F:\WebData\TxtFiles\1.txt")); 
     client.Send(EM2); 

     Dts.TaskResult = (int)ScriptResults.Success; 

     MailMessage EM3 = new MailMessage("[email protected]", "[email protected]", 
     "This is my subject" + " " + " ", "Hello,"); 

     EM3.Attachments.Add(new Attachment(@"F:\WebData\TxtFiles\1.txt")); 
     client.Send(EM3); 
     client.Send(EM3); 

     Dts.TaskResult = (int)ScriptResults.Success; 

    } 
} 

}

+0

現在粘貼代碼。 – Isha

+0

看起來像VB.net代碼。 VB.net和VBScript是不同的語言。 –

+0

謝謝指出。我對此甚爲陌生(甚至是項目)。該代碼是由一位同事編寫的。我應該在不同的標籤下加標籤嗎? – Isha

回答

0

你應該檢查的第一個地方是郵件服務器的日誌。他們應該告訴你所提交的消息(接受/拒絕,下一跳交付等)發生了什麼。

但是,無論如何,將相同的消息多次發送給不同的收件人是不好的做法。這是郵件服務器的工作。爲所有目標收件人僅提交一次郵件。您可以用逗號分隔的字符串指定的所有收件人:

MailMessage EM = new MailMessage("[email protected]", _ 
    "[email protected],[email protected],[email protected]", _ 
    "This is my subject", "Hello,"); 

EM.Attachments.Add(new Attachment(@"F:\WebData\TxtFiles\1.txt")); 
client.Send(EM);

或添加其他收件人是這樣的:

MailMessage EM = new MailMessage("[email protected]", _ 
    "[email protected]", "This is my subject", "Hello,"); 

EM.To.Add("[email protected]"); 
EM.To.Add("[email protected]"); 

EM.Attachments.Add(new Attachment(@"F:\WebData\TxtFiles\1.txt")); 
client.Send(EM);

如果您不希望收件人知道其他的收件人,發送消息發送給默認收件人(例如發件人地址),並將其他收件人添加爲BCC地址:

MailMessage EM = new MailMessage("[email protected]", _ 
    "[email protected]", "This is my subject", "Hello,"); 

EM.Bcc.Add("[email protected]"); 
EM.Bcc.Add("[email protected]"); 
EM.Bcc.Add("[email protected]"); 

EM.Attachments.Add(new Attachment(@"F:\WebData\TxtFiles\1.txt")); 
client.Send(EM);
相關問題