Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
ashish  
#1 Posted : Monday, December 23, 2013 4:48:40 AM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
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...
ivan  
#2 Posted : Monday, December 23, 2013 4:44:25 PM(UTC)
ivan

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.
ashish  
#3 Posted : Monday, December 23, 2013 9:27:19 PM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
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
ashish  
#4 Posted : Monday, December 23, 2013 9:37:21 PM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
Location: Jaipur

Is this any issue with trial version of EA send mail?
ivan  
#5 Posted : Monday, December 23, 2013 9:54:14 PM(UTC)
ivan

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

ashish  
#6 Posted : Monday, December 23, 2013 10:08:09 PM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
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);
}
}

});
}
ivan  
#7 Posted : Monday, December 23, 2013 10:59:27 PM(UTC)
ivan

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 ....
ashish  
#8 Posted : Monday, December 23, 2013 11:05:07 PM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
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 ?
ivan  
#9 Posted : Monday, December 23, 2013 11:14:07 PM(UTC)
ivan

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

ashish  
#10 Posted : Monday, December 23, 2013 11:31:27 PM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
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?
ashish  
#11 Posted : Monday, December 23, 2013 11:32:43 PM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
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

ashish  
#12 Posted : Monday, December 23, 2013 11:46:20 PM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
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
ivan  
#13 Posted : Tuesday, December 24, 2013 12:36:20 AM(UTC)
ivan

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

ashish  
#14 Posted : Tuesday, December 24, 2013 1:04:51 AM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
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 ?
ivan  
#15 Posted : Tuesday, December 24, 2013 1:32:31 AM(UTC)
ivan

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
ashish  
#16 Posted : Tuesday, December 24, 2013 1:36:39 AM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
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
ivan  
#17 Posted : Tuesday, December 24, 2013 1:59:01 AM(UTC)
ivan

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?
ashish  
#18 Posted : Tuesday, December 24, 2013 2:35:46 AM(UTC)
ashish

Rank: Newbie

Groups: Registered
Joined: 12/21/2013(UTC)
Posts: 1
India
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.
Users browsing this topic
Guest
Forum Jump  
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.158 seconds.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.