Emails not sending

Discussion in 'Email' started by puppysmart1, Jul 4, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have some custom code that sends an email when a particular event happens. This is a page with no visual interface, only responds when called from another website, ASP.NET 3.5, yada yada.

    I know the page is firing because it is updating a SQL database properly. Just the email notification is not happening.

    I am using the "no-reply" email address as the sending address. I've used both of these settings in the web.config:

    Code:
    <system.net>
        <mailSettings>
            <smtp>
                <network host="smtpauth.earthlink.net" port="xxx" userName="xxxxxxxx" password="xxxxxxxx"/>
            </smtp>
        </mailSettings>
    </system.net>
    Code:
    <system.net>
        <mailSettings>
            <smtp from="[email protected]" deliveryMethod="Network">
                <network host="localhost" port="25" password="xxxxxxxx" userName="[email protected]" />
            </smtp>
        </mailSettings>
    </system.net>
    And the code I am firing in the page does this:

    Code:
        public void SendMail(string mailFrom, string mailTo, string subjectText, string bodyText)
        {
            System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
    
            mailMessage.From = new MailAddress(mailFrom);
            mailMessage.To.Add(new MailAddress(mailTo));
    
            mailMessage.Subject = subjectText.Trim();
            mailMessage.Body = bodyText.Trim();
    
            SmtpClient smtpClient = new SmtpClient();
            Object userState = mailMessage;
        
            //Attach event handler for async callback
            smtpClient.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);
    
            try
            {
                //Send the email asynchronously
                smtpClient.SendAsync(mailMessage, userState);
            }
            catch (SmtpException smtpEx)
            {
                //Error handling here
            }
            catch (Exception ex)
            {
                //Error handling here
            }
        }
    which uses this for error trapping:
    Code:
        void smtpClient_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
        // Event handler for processing completion information after asynchronous email sent.
    
            //Get UserState as MailMessage instance from SendMail()
            MailMessage mailMessage = e.UserState as MailMessage;
    
            if (e.Cancelled)
            {
                //labMessage.Text = "Sending of email message was cancelled. Address=" + mailMessage.To[0].Address;
            }
    
            if (e.Error != null)
            {
                //labMessage.Text = "Error occured, info=" + e.Error.Message;
            }
            else
            {
                //labMessage.Text = "Mail sent successfully";
            }
        }
     
  2. Hi,
    I can't spot anything wrong other than the possible address building event.
    Have you tried running a test with the message from and to hard coded?
    All the best,
    Mark
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page