• GoDaddy Community
  • Building and Managing a Website
  • Building and Managing a Website

    Showing results for 
    Search instead for 
    Did you mean: 

    How to Configure SMTP correctly?

    Hi, I'm new to building websites and I'm trying out a simple website with a Contact Us page. Basically, the users can just send emails for queries. I've been working on this for hours and tried some of the solutions that worked for others but to no avail, I'm still stuck. Here's some info, these might help you understand my situation.


    Web Hosting: godaddy

    SMTP/Mail Server: Yahoo! 


    I tried changing the web.config file to this:


        <trust level ="Full"/>
        <customErrors mode="Off"/>
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2"/>
        <httpRuntime targetFramework="4.5.2"/>
          <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
          <smtp deliveryMethod="Network" from="<uname@uname.com>">
          <network host="smtp.mail.yahoo.com" port="587" password="<pass>" userName="<uname@uname.com>" defaultCredentials="false"/>
        <validation validateIntegratedModeConfiguration="false"/>
          <remove name="ApplicationInsightsWebTracking"/>
          <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"

    I got the port no: 587 and host: smtp.mail.yahoo.com from the Yahoo settings. It works on the local machine but not on the production server. 


    Here's the vb.net code for this action:

     Protected Sub btn_Send_Click(sender As Object, e As EventArgs) Handles btn_Send.Click
                Dim Smtp_Server As New SmtpClient
                Dim e_mail As New MailMessage()
                Smtp_Server.UseDefaultCredentials = False
                Smtp_Server.Credentials = New Net.NetworkCredential("uname@uname.com", "pass")
                Smtp_Server.Port = 587
                Smtp_Server.EnableSsl = True
                Smtp_Server.Host = "smtp.mail.yahoo.com"
                e_mail = New MailMessage()
                e_mail.From = New MailAddress("uname@uname.com")
                e_mail.Subject = "[" & TextBox1.Text & "]  [" & TextBox3.Text & "] Subject:" & TextBox5.Text
                e_mail.IsBodyHtml = False
                e_mail.Body = "Number: " & TextBox2.Text & vbNewLine & "Company: " & TextBox4.Text & vbNewLine & "Message: " & TextArea1.InnerText
                Msg("Mail Sent")
                e_mail = New MailMessage()
                e_mail.From = New MailAddress("uname@uname.com")
                e_mail.Subject = "Thank you for sending us a message"
                e_mail.IsBodyHtml = False
                e_mail.Body = "Dear " & TextBox1.Text & "," & vbNewLine & "We received your inquiry, Please expect a reply within a few hours. " & vbNewLine & vbNewLine & "Thank you for using the this website. This is a system-generated e-mail. Please do not reply."
                Msg("Mail Sent")
                TextBox1.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                TextBox4.Text = ""
                TextBox5.Text = ""
                TextArea1.InnerText = ""
                btn_Send.Text = "Sent."
            Catch error_t As Exception
                Msg("Error sending: Check entered fields.")
                btn_Send.Text = "Catched error."
            End Try
        End Sub

    Do I need to configure anything else aside from the web.config file and the vb.net code? Am I doing it wrong with the web.config and the code?


    Thanks for those who'll be helping me! Smiley Very Happy




    Re: How to Configure SMTP correctly?

    @doctorallan, the following is what I have in my web.config:


        <smtp deliveryMethod="Network">
          <network host="relay-hosting.secureserver.net" port="25" />

    I forget where the GoDaddy article is at but that is what they say and it works for me. The foolowing is my C#:


        MailMessage mm = new MailMessage();
        mm.To.Add(new MailAddress(ConfigurationManager.AppSettings["MailMessageTo"]));
        mm.From = new MailAddress(TextBoxemail.Text);
        mm.Subject = "Contact Me";
        mm.Body = Message.Text;
        mm.IsBodyHtml = false;
        new SmtpClient().Send(mm);
        TextBoxSuccess.Visible = true;
    catch (Exception ex)
        Result.Text = "Error: " + ex.ToString();
        Result.Visible = true;

    That is relatively simple but it works. You can use that as a guide.


    Re: How to Configure SMTP correctly?

    Thanks for this @SamHobbs. I tried this. But it still didn't work for me. Are you using other emails address where the messages should be sent? Like Yahoo or Google/Gmail? I think I'm going to try your c# code tho. Did you set-up anything else? Or just the codes and the web.config file? Sorry for all the questions.


    Re: How to Configure SMTP correctly?

    @doctorallan, note that I get the "to" address from settings using:


    Did you put your "to" address in the settings? If you don't want to then you can replace that part with the actual email address. The advantage of the settings is that we don't need to modify the code to change the setting.


    The email address I am using is an account for the web site. The site was hosted in GoDaddy but at the moment I was using a different server for email but it is even more likely to work if you are using an email address for the web site and the site is hosted by GoDaddy and the email is using the GoDaddy email server; in other words, nothing unusual.



    Re: How to Configure SMTP correctly?

    @doctorallan, the following is the aspx code for the form, in case this helps you understand the code. Note that TextBoxSuccess and Result are TextBoxes.


    <form id="form1" runat="server">
        Your email address:&nbsp;&nbsp;<asp:TextBox ID="TextBoxemail" runat="server" Width="300px"/>
        <br /><br />
        Your message:<br />
        <asp:TextBox id="Message" TextMode="multiline" Columns="60" Rows="20" runat="server" />
        <br />
        <br />
        <asp:Button ID="ButtonSend" runat="server" Text="Send"  />
        &nbsp;<asp:TextBox ID="TextBoxSuccess" runat="server" Width="98px" Visible="False">Message sent.</asp:TextBox>
        <br />
        <br />
        <asp:TextBox id="Result" TextMode="multiline" Columns="60" Rows="20" runat="server" Visible="False" />

    Except the ButtonSend button has an "OnClick" for "ButtonSend_Click". For some reason this forum software does not allow code to be posted that looks like that.