locked
Failure sending mail with ASP.NET 2.0

    Question

  • Hi:

    I have been receiving a “Failure sending mail” when I try to send an email from a form using the ASP.NET 2.0 code below.  It works fine on a test server on our network but the error occurs when I put it on our production server (both Windows 2003 and IIS 6).  I also have an upload function on the form that works fine on both sites.

     

    The form is on a virtual site under a site using ASP.NET1 and the email works fine on that site.  In the Web.Config the authentication is set to none (for anonymous access).  When I first set ASP.NET 2 on the site I had to add asp machine user account to the permissions to get the aspx pages to work  so I am wondering if it is a permissions issue.  Also the Inetpub fodler is not on the C drive but on a D drive if that makes a difference.

     

    The code is:

     

    Dim fromaddress As New MailAddress("email@somewhere.com", "Estimate Request")

            Dim toaddress As New MailAddress("email@ somewhere.com ")

            Dim message As New MailMessage(fromaddress, toaddress)

       

     

            message.Body = ("Name:" & "  " & txtfName.Text & " " & txtlName.Text & "<br>" & "Company:" & "  " & txtCompany.Text & "<br>" & "Email:" & "  " & txtEmail.Text & "<br>" & "Phone:" & "  " & txtPhone.Text & "<br>" & "Instructions:" & "  " & txtInstructions.Text & "<br>" & "File Details:" & "  " & Label1.Text & "<br>" & "Language To:" & "  " & DlistTo.Text & "<br>" & "Source Language:" & "  " & DlistFrom.Text)

            message.Subject = "Request for an estimate, sent at " & DateTime.Now.ToString()

            message.IsBodyHtml = True

           

            Dim mailsender As New System.Net.Mail.SmtpClient()

           

            mailsender.Host = "localhost"

            mailsender.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis

          

                  

            Try

                mailsender.Send(message)

                lbl1.Text = "Thank you! Your file has been sent and an account manager will contact you within one business day."

            Catch ex As Exception

                lbl1.Text = ex.Message

            End Try

           

        End Sub

     

    Any Suggestions?

     

    Thanks

     

    Thursday, February 16, 2006 6:47 PM

Answers

  •  

    1. Why are you setting the location to the pick up directory from IIS?
    2. Do you have an SMTP service installed on that computer [in production machines]

    The issue is that you need to have SMTP server installed to be able to
    find the pick up directory. There could also be some registry key permission issues.
    I suggest that you send it to a real SMTP server [perhaps to the test box you have]
    If that works then you definitley have a permissions issue

    Friday, February 17, 2006 6:04 PM
    Moderator

All replies

  •  

    1. Why are you setting the location to the pick up directory from IIS?
    2. Do you have an SMTP service installed on that computer [in production machines]

    The issue is that you need to have SMTP server installed to be able to
    find the pick up directory. There could also be some registry key permission issues.
    I suggest that you send it to a real SMTP server [perhaps to the test box you have]
    If that works then you definitley have a permissions issue

    Friday, February 17, 2006 6:04 PM
    Moderator
  • i have the same question now! i want to use a third party SMTP Server, i also doesn't  know How do I specify username and password for the mail server out there.

    Please give me a piece of advices, Thanks a lot!

    Monday, February 20, 2006 8:07 AM
  • Please don't hijack threads.
    Post your issue in a new thread.

    Monday, February 20, 2006 4:45 PM
    Moderator
  •  

    Yes, I do have SMTP service installed on the production machine and it does work with other web apps on the same site.  I will try sending it to another SMTP server and let you know (do I need to configure anything for relay in the SMTP configuration?)

    As far as the IIS pickup, there were three choices I saw with the smtpdeliverymethod, the IIS pickup directory, network and specify a pickup diectory, it was an abitary choice honestly and worked on the test enviroment.

    Thanks for your help

    Jim

    Tuesday, February 21, 2006 5:29 PM
  • As a followup

    When I use another remote SMTP server and comment out the SMTPDeliveryMethod the email will work, so where would the permissions issue be?

    Thanks

    Jim

    Tuesday, February 21, 2006 6:49 PM