Need help for a Simple Email App using ASP/SMTP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mturner64
    New Member
    • Feb 2007
    • 49

    Need help for a Simple Email App using ASP/SMTP

    I'm working on a simple web app to send email. Below is my code:

    Code:
    Imports System.Net.Mail
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
    
            Dim FromAddress As String = "mturner64@student.se.edu"
    
            'Create the MailMessage instance
            Dim email As New System.Net.Mail.MailMessage(FromAddress, ToTextBox.Text)
    
            'Assign the MailMessage's properties
            email.Subject = SubjectTextBox.Text
            email.Body = BodyTextBox.Text
            email.IsBodyHtml = False
    
            'add attachment
            email.Attachments.Add(New Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName))
    
            'Create the SmtpClient object
            Dim smtp As New SmtpClient
    
            'Send the MailMessage (will use the Web.config settings)
            smtp.Send(email)
            smtp.Host = "mail.se.edu"
            
    
        End Sub
    I have added the following code to my webconfig file:

    Code:
    <system.net>
        <mailSettings>
          <smtp from="mturner64@student.se.edu">
            <network host="mail.se.edu"/>
          </smtp>
        </mailSettings>
      </system.net>

    The error I get is as follows:

    A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 164.58.120.84:2 5

    WHAT TO DO?
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi mturner64,

    Firstly, you've posted this in the ASP forum which is for Classic ASP only. I'm moved the thread to the .NET forum where you should receive better help.

    As for your question, the problem here is probably the connection to your mail host. I'm not 100% sure about this one but you might need to set the Host property of your smtp object before using the Send method.

    Also, can you try pinging that host name from the machine which hosts your web pages? It could be a problem with the DNS resolving the name - have you tried using the IP address of your mail server instead?

    Dr B

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      What errors are you getting? The SMTP server should send you an error code and possibly a short message describing the error.

      You need to make sure you have a few things first:
      1) Does you email host allow smtp connections?
      2) Do you have the correct hostname for the smtp server?
      3) Does your SMTP host require authentication to send mail (most do)?

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        i think you might want to swap these 2 lines
        Code:
        'Send the MailMessage (will use the Web.config settings)
        smtp.Send(email)
        smtp.Host = "mail.se.edu"
        and make it
        Code:
        'Send the MailMessage (will use the Web.config settings)
        smtp.Host = "mail.se.edu"
        smtp.Send(email)
        though this wouldnt help much as you already speified the settings in the config file

        Comment

        Working...