2012-01-14 79 views
2

我有一個win服務器2003 3 ips,我正在做一個程序,發送大量的郵件,但我想在發送電子郵件時在3 ips之間切換,比如說,第一封郵件發送使用第一個IP和第二封郵件使用第二個IP和第三封郵件使用第三個IP,我知道如何發送郵件使用C#,但有沒有任何類選擇開關IP或什麼的,我其實不期待代碼,我想任何所以我可以開始挖掘的想法。每次發送郵件時使用不同的IP

+1

如何設置了三個郵件服務器(例如[hMailServer](http://www.hmailserver.com/)),每個IP地址都有一個工作。 [據作者說,這是可能的](http://www.hmailserver.com/forum/viewtopic.php?f=10&t=13600)。然後你的C#代碼可以與樹進行通信。 – 2012-01-14 15:18:53

+1

此外,還有[SF上的類似問題](http://serverfault.com/questions/134568/how-to-send-mail-with-hmailserver-from-different-ips-for-different-domains)可能對你有幫助。 – 2012-01-14 15:19:16

+1

你爲什麼要這麼做? – 2012-01-14 15:19:30

回答

3

3個IP是不夠的。你有3個郵件服務器使用3 ips嗎?如果是的話,這是可能的。

我會用Random ...

Random r = new Random(); 
int mailServer = r.Next(1, 3); 
SmtpClient client; 

if (mailServer == 1) client = new SmtpClient("mail1.yourdomain.com"); 
else if (mailServer == 2) client = new SmtpClient("mail2.yourdomain.com"); 
else client = new SmtpClient("mail3.yourdomain.com"); 

client.Send(...); 
+0

這就是一個很好的例子,非常感謝,我雖然切換ips,但這看起來也很棒。 – 2012-01-14 20:06:04

+0

很高興幫助!祝你今天愉快! – dknaack 2012-01-14 20:52:41

1

SmtpClient構造函數,你知道你的接受服務器的地址,所以你可以使用它的方式

class Program 
{ 
    static string[] addresses = new string[] 
     { "192.168.0.1", "215.100.100.100", "110.100.100.100" }; 

    static void Main(string[] args) 
    { 
     SmtpClient server1 = GetClient(0); 
     // stuff to send mail with 1st server 
     SmtpClient server2 = GetClient(1); 
     // stuff to send mail with 2nd server 
     // etc. 

    } 

    private static SmtpClient GetClient(int id) 
    { 
     if (addresses[id] != null) 
      return new SmtpClient(addresses[id]); 
     throw new ArgumentException("No such server"); 
    } 
} 
相關問題