Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
I am sending bulk emails using Parallel Task.When 'From Mail Id' and 'To Mail Id' are same then I got duplicate mails on To Mail Id. I used SendEmail(SmtpServer server, SmtpMail mail) method to send mail. Any suggestions...
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, you can use LogFileName property to generate a log file. then you can check the log file. You can find RCPT TO: xxxxx If there is only one RCPT TO, that means you only sent the email to the recipient once, if you still get two emails, that means your server duplicates the email. If there are one more RCPT TO, please check if you add the same recipient multiple times in your codes.
Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
Hi, I have these logs in log file ,I have got 8 mails while recipient only four and log shows three recipients MAIL FROM:<ashu.sajwan385@gmail.com> 235 2.7.0 Accepted MAIL FROM:<ashu.sajwan385@gmail.com> 235 2.7.0 Accepted MAIL FROM:<ashu.sajwan385@gmail.com> 250 2.1.0 OK oj6sm50418535pab.9 - gsmtp RCPT TO:<ashu.sajwan385@gmail.com> 250 2.1.0 OK ki1sm38481904pbd.1 - gsmtp RCPT TO:<ashu.sajwan385@gmail.com> 250 2.1.0 OK sd3sm38402247pbb.42 - gsmtp RCPT TO:<ashu.sajwan385@gmail.com> 250 2.1.5 OK er3sm38405830pbb.40 - gsmtp
Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
Is this any issue with trial version of EA send mail?
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,154
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
Could you show me your source code?
If you re-use Mail instance, after called SendMail, please remember to call
oMail.To.Clear();
To remove current recipients and add new recipients to send another email.
Edited by user Monday, December 23, 2013 9:59:55 PM(UTC)
| Reason: Not specified
Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
Hello Ivan, Please check below code ,I am using this code to send email When sender and receiver are same. for (int i = 0; i < MaxThreads; i++) { tasks[i] = Task.Factory.StartNew(() => { while (!PendngMails.IsCompleted) { SmtpClient mailSmtp = null; try { var item = PendngMails.Take(); mailSmtp = new SmtpClient(); mailSmtp.RcptToErrorContinue = true; mailSmtp.Tag = item; SmtpMail oMail = new SmtpMail("TryIt"); string defultsender = "Dummy Email"; oMail.From = new MailAddress("" + defultsender + "<" + item.MailFrom + ">"); oMail.To = item.MailTo; oMail.Subject = "Test Email"; oMail.TextBody = "This is test email."; SmtpServer oServer = new SmtpServer("smtp.gmail.com"); oServer.Protocol = ServerProtocol.SMTP; oServer.User = item.MailFrom; oServer.Password = item.Emailpwd; ; oServer.ConnectType = SmtpConnectType.ConnectSSLAuto; mailSmtp.LogFileName = @"C:\Log.txt"; mailSmtp.SendMail(oServer, oMail); oMail.To.Clear(); Console.WriteLine("Mail sent"); _CrossThreadSetItemText(mailSmtp.Tag, "Success"); } catch (Exception ex) { _CrossThreadSetItemText(mailSmtp.Tag, ex.Message); } } }); }
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,154
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
You are using multiple threads in your codes: for (int i = 0; i < MaxThreads; i++) You send the same email for MaxThreads times. If you only want to send one email, please don't use for ....
Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
I want to send multiple email so i used MaxThreads here. Is there any solution of this problem which can prevent duplicate email when From=To ?
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,154
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
sure it is possible.
But please tell me what is PendngMails and Item.To? Is it an array?
Edited by user Monday, December 23, 2013 11:24:14 PM(UTC)
| Reason: Not specified
Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
When i use simple email code with c# using above sample code the no duplicate mails send even From=To. Then why this issue occur when use your code to send email?
Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
PendngEmail is BlockingCollection of Email class.
Item reference of Email class.
Edited by user Monday, December 23, 2013 11:33:45 PM(UTC)
| Reason: Not specified
Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
As you saw our sample code we use Console.WriteLine("Mail sent"); Its shows only 4 times if i want send 4 mails. PendngMails.Take don't take duplicated emails,BlockingCollection is also thread safe. Same code works smooth with System.Net.Mail
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,154
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
I just wrote a simple project, but it works fine.
Here are my codes:
Code:
namespace BlockSending
{
class Program
{
static void Main(string[] args)
{
MailSending send = new MailSending();
send.Test();
}
}
class MailSending
{
BlockingCollection<string> PendngMails = new BlockingCollection<string>() ;
public void Test()
{
for (int i = 0; i < 4; i++)
{
PendngMails.Add("ivan@mydomain.com");
}
PendngMails.CompleteAdding();
Task[] tasks = new Task[10];
for (int i = 0; i < 10; i++)
{
tasks[i] = Task.Factory.StartNew(() =>
{
while (!PendngMails.IsCompleted)
{
SmtpClient mailSmtp = null;
try
{
var item = PendngMails.Take();
mailSmtp = new SmtpClient();
mailSmtp.RcptToErrorContinue = true;
mailSmtp.Tag = item;
SmtpMail oMail = new SmtpMail("TryIt");
string defultsender = "Dummy Email";
oMail.From = new MailAddress("" + defultsender + "<" + item + ">");
oMail.To = item;
oMail.Subject = "Test Email";
oMail.TextBody = "This is test email.";
SmtpServer oServer = new SmtpServer("localhost");
oServer.Protocol = ServerProtocol.SMTP;
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
//mailSmtp.LogFileName = @"C:\Log.txt";
mailSmtp.SendMail(oServer, oMail);
oMail.To.Clear();
Console.WriteLine("Mail sent");
// _CrossThreadSetItemText(mailSmtp.Tag, "Success");
}
catch (Exception ex)
{
// _CrossThreadSetItemText(mailSmtp.Tag, ex.Message);
}
}
});
}
System.Threading.Tasks.Task.WaitAll(tasks);
}
}
}
So could you send me your project so that I can have a test?
Another possibility is:
Here are two email addresses in Item.MailTo
you can add:
Console.WriteLine("Mail sent");
Console.WriteLine( Mail.To.ToString());
to see how many email addresses in Mail.To
Edited by user Tuesday, December 24, 2013 12:44:57 AM(UTC)
| Reason: Not specified
Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
Hello Ivan, I also try sample code with localhost its work fine, Can you try same code when server is smtp.gmail.com and FROM=TO ?
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,154
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
Yes, I just tested it with my gmail account, no duplicated emails. Another possibility is: Here are two email addresses in Item.MailTo you can add: Console.WriteLine("Mail sent"); Console.WriteLine( Mail.To.ToString()); to see how many email addresses in Mail.To
Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
I used your code mentioned in your comment. Console.WriteLine("Mail sent"); Console.WriteLine( Mail.To.ToString()); Here is output window trace log: 'TestApp.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Mail sent <ashu.sajwan385@gmail.com> A first chance exception of type 'System.NullReferenceException' occurred in TestApp.exe Mail sent <ashu.sajwan385@gmail.com> A first chance exception of type 'System.NullReferenceException' occurred in TestApp.exe A first chance exception of type 'System.NullReferenceException' occurred in TestApp.exe Mail sent <ashu.sajwan385@gmail.com> A first chance exception of type 'System.NullReferenceException' occurred in TestApp.exe Mail sent <ashu.sajwan385@gmail.com> The thread '<No Name>' (0x1cc8) has exited with code 0 (0x0). The thread '<No Name>' (0x15ec) has exited with code 0 (0x0). The thread '<No Name>' (0x1808) has exited with code 0 (0x0). The thread '<No Name>' (0x1b7c) has exited with code 0 (0x0). But still mails are duplicate
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,154
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
I am sorry, it is really weird Console.WriteLine("Mail sent"); Console.WriteLine(mailSmtp.SmtpConversation); this displays SMTP conversation, you can see how many RCPT TO sent for each SMTP conversation. It is only about your gmail account or every email with same From, To?
Rank: Newbie
Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
Location: Jaipur
Hi Ivan, I noticed that this issue occurs with my gmail account not with others. If I come across with any issue, I will let you know. Thanks for answering my questions patiently.
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.