2013-12-11 31 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);
相关问题