tags:

views:

1216

answers:

1

Hi

I think i need some guru lights!

public void SendEndingMail(string fileName)
        {
            SmtpClient client;
            client = new SmtpClient("smtp.myserver.com", 25);
            //client = new SmtpClient();
            if (!string.IsNullOrEmpty(""))
            {
                System.Net.NetworkCredential credential = new NetworkCredential("", "");
                client.Credentials = credential;
            }
            client.UseDefaultCredentials = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            //client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

            MailAddress fromAddress = new MailAddress("[email protected]", "Elec");
            MailAddress toAdrress = new MailAddress("[email protected]");

            using (System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(fromAddress, toAdrress))
            {

                mailMessage.Attachments.Add(new System.Net.Mail.Attachment(fileName));
                mailMessage.IsBodyHtml = false;
                mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
                try
                {
                    client.Send(mailMessage);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }

Is that true that: when i set client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; It does not matter whichever smtp server i use

        client = new SmtpClient("smtp.myserver.com", 25);
        //client = new SmtpClient();

The both lines are the same since it will use LOCAL IIS ?!!!

Is this is true, it is not normal that the API is build this way!? it is very confusing...

Thanks Jonathan

A: 

Hi,

IIRC, when the SmtpClient sends the email, it looks at the .DeliveryMethod value. If the value is Network, then it sends via network. If it is PickupDirectoryFromIis, then it ignores any specified SMTP server (because it just writes and the email to the filesystem), and writes it to the Pickup directory. No network communication takes place.

Cheers!

Dave

dave wanta
Thanks Dave but i do not understand the last sentence "and writes it to the Pickup directory. No network communication takes place." where is the magic? it must be sent through an smtp server ?
Hi,The SmtpClient will write the email directly too the pickup directory. Once it is written, the IIS SMTP service will come by, analyze the mail, if it accepted, it gets moved to the Queue directory. From there, the message is sent on, either to a smart host, or to the recipient's mail server.Cheers!Dave
dave wanta
When I say "From there", I mean the IIS SMTP service will then attempt to delilver the message. If the message can't be delivered, it stays in the Queue for possible delivery retries. Or, if delivery fails entirely, it gets moved to the Badmail directory. --Dave
dave wanta
So why microsoft allows to put a smtp server in the creation of the smtpclient if not used when user sets the pickup option....