tags:

views:

644

answers:

3

Hi,

When using the following code to send an email message to an external e-mail address via IIS6 SMTP I am receiving a message stating that the message has been sent, but it never arrives at the destination. I'm using the System.Net.Mail namespace and the following code:

MailMessage msg = new MailMessage();
msg.From = new MailAddress(from);

foreach (string strTo in to.Split(';'))
{
  if (strTo.Replace(";", "") != string.Empty)
    msgMailSummary.To.Add(new MailAddress(strTo.Replace(";", "")));
}
msg.Subject = subject;
msg.Body = body;

SmtpClient sm = new SmtpClient();
sm.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
sm.Credentials = new NetworkCredential(tbUsername.Text, tbPassword.Text);
sm.Host = host;
sm.Port = port;
sm.Send(msg);

I don't have a SmartHost setup in IIS6, is there any obvious or any hints,tips that I can check out to get this working?

+2  A: 

Umm, you seem to be missing one key line...

msg.To = new MailAddress(to);
Robin Day
Your right, he is. hehe
Jon
haha, classic :)
ck
That would be embaressing! Got carried away stripping out all my code before posting, the code has this line:foreach (string strTo in to.Split(';')){ if (strTo.Replace(";", "") != string.Empty) msgMailSummary.To.Add(new MailAddress(strTo.Replace(";", "")));}Any new suggestions?
Fermin
A: 

I am not sure if I remember right, but I once had a problem where I couldn't send an email because my From address was not what my hosting allowed. Basically I ended up being able to only set ReplyTo and leaving From undefined (the smtp server will define it by itself). Try it, it might work.

niaher
I'll check it out tomorrow and let you know!
Fermin
I tried removing the FROM address undefined but I receive and error saying that the From address is missing...
Fermin
A: 

Turned out it was the setup on the server wasn't configured correctly. Thanks for your help tho.

Fermin