You have to realize that the return code for the method only indicates that
it sent your message to the next system in the chain. This doesn't mean
that the message actually got all the way to the designated recipient.
Check your mail system logs for errors to get more information on what went
wrong.
...Glenn
On Mon, Nov 17, 2008 at 6:59 AM, stapes <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> I am trying to send emails using the following method:
>
> protected void Button1_Click(object sender, EventArgs e)
> {
> // this method of sending emails comes from
>
> http://weblogs.asp.net/nawaf/archive/2007/12/07/sending-email-in-c-sync-async-multiple-recipients-attachments-etc.aspx
>
> //string from = "[EMAIL PROTECTED]";
> string from = "[EMAIL PROTECTED]";
> string to = "[EMAIL PROTECTED]";
> string subject = "Email from EMMA";
> string messageBody = "The quick brown fox";
> Attachment attachmnts=null ;
> SendAsync(from, to, subject, messageBody, attachmnts);
>
> }
> private delegate void SendMailMethod(SmtpClient smtpClient,
> MailMessage message);
> public static void SendAsync(string from, string to, string
> subject, string messageBody, params Attachment[] attachments)
> {
> try
> {
> Send(from, new string[] { to }, subject, messageBody,
> true,
> delegate(SmtpClient smtpClient, MailMessage message)
> { smtpClient.SendAsync(message, DateTime.Now.ToString()); },
> attachments);
> }
> catch (Exception Ex) { CIOS.Utils.MsgBox(Ex.ToString()); }
> }
> private static void Send(string from, string[] to, string subject,
> string messageBody, bool isBodyHtml, SendMailMethod sendDelegate,
> params Attachment[] attachments)
> {
>
> SmtpClient emailClient;
> try
> {
> emailClient = new SmtpClient("checkitout.co.uk");
> MailMessage message = new MailMessage();
> message.Subject = subject;
> message.Body = messageBody;
> message.Sender = new MailAddress(from);
> foreach (string address in to)
> message.To.Add(new MailAddress(address));
> message.IsBodyHtml = isBodyHtml;
> message.BodyEncoding = System.Text.Encoding.UTF8;
> message.SubjectEncoding = System.Text.Encoding.UTF8;
> //if (attachments != null)
> //{
> // foreach (Attachment attchment in attachments)
> // message.Attachments.Add(attchment);
> //}
> //emailClient.UseDefaultCredentials = true;
> emailClient.Credentials =
> System.Net.CredentialCache.DefaultNetworkCredentials;
>
> sendDelegate(emailClient, message);
> CIOS.Utils.MsgBox("Message Sent");
> }
> catch (Exception ex)
> {
> CIOS.Utils.MsgBox(ex.ToString());
> throw new Exception("Unable to send email");
> }
> }
>
> The whole thing appears to run OK and the system responds with
> "Message Sent". However, the message has not been sent. This is a bit
> crap. Why does it say it has worked when it hasn't?
>
> I am using Visual Studio 2005, and IIS version 5.1
>
> Any ideas how I can get this to work?