Email problem from web site

Discussion in 'Visual Studio' started by ExpressShipping, Aug 17, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Using vs 2010 and trying to get website to send me an email on load. Got it to work yesterday but I must have changed something. Build and Publish work fine.

    Have this code in my Web.config,

    <system.net>
    <mailSettings>
    <smtp from="[email protected]">
    <network host="localhost" port="25"
    userName=""
    password=""
    defaultCredentials="true" />
    </smtp>
    </mailSettings>
    </system.net>


    And this code in Email.aspx,

    Imports System.Net.Mail
    Public Class Email
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim myMessage As MailMessage = New MailMessage()
    myMessage.Subject = "Test message"
    myMessage.Body = "Hello world"
    myMessage.From = New MailAddress("[email protected]", "John Doe")
    myMessage.To.Add(New MailAddress("[email protected]", "John Doe"))

    Dim mySmtpClient As SmtpClient = New SmtpClient()
    mySmtpClient.Send(myMessage)

    End Sub

    End Class


    Thanks

    FM
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    what problem are you seeing?
     
  3. Sorry for the delay in responding. I decided to read the first 8 chapters of Beginning Wrox ASP.Net instead of skipping to the part about sending emails.

    Using the test email contact form at aex1.com.
    I used the same code in the web config file as before, but I do not receive the emails. Should I be using "[email protected]" or my email [email protected]? Should I leave the username and password blank? I am using port 587 in the setup of Outlook if that matters. Received the following error message from earlier attempts,
    Could not deliver message to the following recipient(s):

    Failed Recipient: [email protected]
    Reason: Remote host said: 601 Attempted to send the message to the following ip's:
    216.239.122.34


    <system.net>
    <mailSettings>
    <smtp from="[email protected]">
    <network host="localhost" port="25"
    userName=""
    password=""
    defaultCredentials="true" />
    </smtp>
    </mailSettings>
    </system.net>

    Thanks
    FM
     
  4. Got it working. Helps when you enter your email in the code behind of the contact form. Embarrassing.
     
  5. mjp

    mjp

    It's always the seemingly obvious stuff that slips by.
     
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