I wouldn't go so far as to call it crap. Things like Email are
dependent on a lot of factors, for instance, the presence of a
correctly configured mail server.

On Nov 17, 4:59 pm, 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 
> fromhttp://weblogs.asp.net/nawaf/archive/2007/12/07/sending-email-in-c-sy...
>
>         //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?

Reply via email to