Rank: Newbie
Groups: Registered
Joined: 9/4/2015(UTC) Posts: 0
Thanks: 1 times
hello, I am currently developing an application in c# using easendmail, all is working fine , but i have one problem he send all email in the same time, i not want that , i want he send the first email than take 3 second and send the next email : this my code : List<string> arRcpt = new List<string>(logFile); int nRcpt = arRcpt.Count; SmtpMail[] arMail = new SmtpMail[nRcpt]; SmtpClient[] arSmtp = new SmtpClient[nRcpt]; SmtpClientAsyncResult[] arResult = new SmtpClientAsyncResult[nRcpt]; List<ServerSocks> list = loadSocks(); var oServer = new SmtpServer(""); for (int i = 0; i < nRcpt; i++) { oServer.SocksProxyServer = list[i%list.Count].IpAddress.ToString(); oServer.SocksProxyPort = list[i%list.Count].Port; oServer.ProxyProtocol = SocksProxyProtocol.Socks5; arMail[i] = new SmtpMail("TryIt"); arSmtp[i] = new SmtpClient(); SmtpMail oMail = arMail[i]; oMail.From = ""; oMail.Style = MailStyle.EASendMailStyle; oMail.HeaderEncoding = HeaderEncodingType.EncodingBase64; oMail.Subject = ""; oMail.TextBody = ""; oMail.AutoTextBody = false; try { string fileHtml = Path.GetFullPath(Path.Combine(Application.StartupPath, "letter.html")); oMail.ImportHtmlBody(fileHtml, ImportHtmlBodyOptions.NoOptions); } catch (Exception ex) { Console.WriteLine(ex); } SmtpClient oSmtp = arSmtp[i]; arResult[i] = oSmtp.BeginSendMail(oServer, oMail, null, null); Console.WriteLine(String.Format("Start to send email to {0} ...", arRcpt[i])); } // All emails were sent by BeginSendMail Method // now get result by EndSendMail method int nSent = 0; while (nSent < nRcpt) { for (int i = 0; i < nRcpt; i++) { // this email has been sent if (arResult[i] == null) continue; // wait for specified email ... if (!arResult[i].AsyncWaitHandle.WaitOne(20, flase)) { continue; } try { // this email is finished, using EndSendMail to get result arSmtp[i].EndSendMail(arResult[i]); Console.WriteLine(String.Format("Send email to {0} successfully", arRcpt[i])); } catch (Exception ep) { Console.WriteLine( String.Format("Failed to send email to {0} with error {1}: ", arRcpt[i], ep.Message)); Console.ReadLine(); } // Set this email result to null, then it won't be processed again arResult[i] = null; nSent++; } } } if i send all the email in the same time he stop send email, and give me the error too much connections 421 what i should do ??? tnks
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,154
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
Hi, it seems that remote SMTP server limit concurrent connections number, so I suggest that you only use one SmtpClient instead of SmtpClient array.
please have a look at the following codes:
Code:
List<string> arRcpt = new List<string>(logFile);
int nRcpt = arRcpt.Count;
SmtpClient oSmtp = new SmtpClient();
SmtpClientAsyncResult oResult = null;
List<ServerSocks> list = loadSocks();
var oServer = new SmtpServer("");
for (int i = 0; i < nRcpt; i++)
{
oServer.SocksProxyServer = list[i % list.Count].IpAddress.ToString();
oServer.SocksProxyPort = list[i % list.Count].Port;
oServer.ProxyProtocol = SocksProxyProtocol.Socks5;
SmtpMail oMail = new SmtpMail("TryIt");
oMail.From = "";
oMail.Style = MailStyle.EASendMailStyle;
oMail.HeaderEncoding = HeaderEncodingType.EncodingBase64;
oMail.Subject = "";
oMail.TextBody = "";
oMail.AutoTextBody = false;
try
{
string fileHtml = Path.GetFullPath(Path.Combine(Application.StartupPath, "letter.html"));
oMail.ImportHtmlBody(fileHtml, ImportHtmlBodyOptions.NoOptions);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
oResult = oSmtp.BeginSendMail(oServer, oMail, null, null);
Console.WriteLine(String.Format("Start to send email to {0} ...",
arRcpt[i]));
// wait for specified email ...
while (!oResult.AsyncWaitHandle.WaitOne(20, false))
{
continue;
}
try
{
// this email is finished, using EndSendMail to get result
oSmtp.EndSendMail(oResult);
Console.WriteLine(String.Format("Send email to {0} successfully",
arRcpt[i]));
}
catch (Exception ep)
{
Console.WriteLine(
String.Format("Failed to send email to {0} with error {1}: ",
arRcpt[i], ep.Message));
Console.ReadLine();
}
System.Threading.Thread.Sleep(1000 * 3); // sleep 3 seconds
}
1 user thanked ivan for this useful post.
Forum Jump
EmailArchitect Support
Email Component Development
- EASendMail SMTP Component - .NET Version
- EASendMail SMTP Component - Windows Store Apps
- EASendMail SMTP ActiveX Object
- EAGetMail POP3 & IMAP4 Component - .NET Version
- EAGetMail POP3 & IMAP4 ActiveX Object
Exchange Server and IIS SMTP Plugin
- DomanKeys/DKIM for Exchange Server and IIS SMTP
- Disclaimer and S/MIME for Exchange Server and IIS
EmailArchitect Email Server
- EmailArchitect Email Server (General)
- EmailArchitect Email Server Development
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.