我有一个带有3个ip的win服务器2003,我正在编写一个发送批量邮件的程序,但我想在发送电子邮件时在3个ip之间切换,例如,使用第一个ip发送第一封邮件,使用第二个ip发送第二封邮件,使用第三个ip发送第三封邮件,我知道如何使用C#发送邮件,但是否有任何类选择交换机ip或其他什么,我实际上不期望代码,我想要任何想法,以便我可以开始挖掘。
发布于 2012-01-14 23:18:09
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(...);发布于 2012-01-14 23:29:38
如您所知,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");
}
}https://stackoverflow.com/questions/8863074
复制相似问题