Failure to send email

Discussion in 'ASP.NET 2.0' started by glenharvy, Jan 12, 2009.

  1. Hi,

    Here is at least part of my c# code that's supposed to send an email to a client:




    SmtpClient myMailClient = new SmtpClient();
    MailMessage myMailMessage = new MailMessage();
    string address = "";
    try

    string mailHost = "smtp.aquarius.com.au";
    string userName = "xxxxxx";
    string password = "xxxx";
    string fromName = "Sales";
    string fromAddress = [email protected];
    string emailBody = "";

    emailBody = "Hi #firstName# etc etc etc"

    myMailMessage.To.Add(new MailAddress(address, fullName));
    myMailMessage.Bcc.Add(new MailAddress("[email protected]", "Sales Department"));
    // Obtains the e-mail address of the person sending the message.
    myMailMessage.From = new MailAddress(fromAddress, fromName);
    // Obtains the subject of the e-mail message
    myMailMessage.Subject = productName + " Licence Purchase";
    myMailMessage.Body = emailBodyPersonalised;
    myMailMessage.IsBodyHtml = true;
    myMailMessage.Priority = MailPriority.High;
    myMailMessage.Attachments.Add(new Attachment(licenceFileName));
    myMailClient.Host = mailHost;
    myMailClient.Port = 25;
    myMailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    // Initializes a new instance of the System.Net.NetworkCredential class.
    NetworkCredential myMailCredential = new NetworkCredential();
    myMailCredential.UserName = userName;
    myMailCredential.Password = password;
    myMailClient.UseDefaultCredentials = false;
    myMailClient.Credentials = myMailCredential;
    try
    {
    myMailClient.Send(myMailMessage);
    }
    catch (SmtpException exSmtp)
    {
    logger.FatalException("Mail failed - SMTP Error: " +address +" | ", exSmtp);
    }
    catch (Exception exGen)
    {
    logger.FatalException("SendingMailFailed_General Exception", exGen);
    }
    finally
    {
    myMailMessage.Attachments.Dispose();
    }


    As far as I can tell, all the information is collected and properly assigned however the email to the orginal recipient fails to be delivered. My generated log entry shows the following:


    System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: web139.discountasp.net (web139) [64.209.135.9]:3013 is currently not


    The error message is trucated for some reason but assumably follows on with ' not available'.


    The blind carbon copy is delivered no problems.


    I have confirmed the To: address is valid and properly formatted.



    Can someone please give me some suggestions as to where I should look to find the source of the problem.


    TIA>
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Since you are using a 3rd party SMTP server, you should check w/ them to see what the problem is. They should have a log of the SMTP conversation.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     

Share This Page