Problem sending two different emails with one SmtpClient

What I need to do is send two emails. The emails are different in content, but get sent one right after the other. I would like to use a single SmtpClient to send both, since it doesn't make sense that I should need to create two objects. Here's is what I am currently doing.

Dim message As New Aspose.Network.Mail.MailMessage
message.From = "from email"
message.To.Add("to email")
message.Subject = "message 1"
message.HtmlBody = "

this is message 1

"

Dim smtp As New Aspose.Network.Mail.SmtpClient("my mail server")
smtp.AuthenticationMethod = Aspose.Network.Mail.SmtpAuthentication.None
smtp.Send(message)

message = New Aspose.Network.Mail.MailMessage
message.From = "from email 2"
message.To.Add("to email 2")
message.Subject = "message 2"
message.HtmlBody = "

this is message 2

"

smtp.Send(message)

The problem with the above code is that only the first email gets sent. I don't receive any error on the second message, it simply is not sent. If I add:

smtp.AuthenticationMethod = Aspose.Network.Mail.SmtpAuthentication.None

right before the second "smtp.Send(message)" line, then the 2nd message gets sent. This seems a little odd to me, since I already defined this property for my smtp object. I'm guessing that something happens internally to your SmtpClient class that resets something, preventing the same SmtpClient from being able to send more than one message. Please look into this and fix it. I'll use my work around temporarily.

Thanks!

Dan

Hi Dan,

I did some tests using the code above. It gave an "Authentication Failure" exception one time. But all other tests were seccuessful and both messages were sent.

It could be a Network error I guess.

Could you please try your code a few times without setting smtp.AuthenticationMethod property twice. Just set it only once.

The SMTP server should also be able to authenticate "From Email Address" in both the messages, based on SMTP authentication settings.

Saqib,

I actually had tested it quite extensively on two different servers (two different code servers and two different smtp servers) and got the same results on both. The only way I can get it to work is by adding that 2nd authentication line.

Also, it will not authenticate at all without the authentication method being set to "none", even if I am just sending one message.

I don't know if this will help at all (I'm not an email expert), but I am using an SMTP virtual server, not a full mail server to send these emails.

Please let me know if you can find any other explanation for this behavior.

Thanks!

Dan

Hello, Dan,

Could you please provide your smtp server for our debugging and bug reproducing? My email box is guangzhou##aspose.com. I will use your smtp server only for the debugging purpose.

Thanks

iret,

As you can imagine, I am not able to open access for you to our smtp server. It is a standard smtp server running on Windows Server 2003 Standard Edition. The smtp server access is locked down by IP address.

If I can provide any other information that will help you, please let me know.

I will continue to use the workaround in the meantime.

Dan