ASP.NET: Send mail html format – Email settings for godday hosting

  1. It is always better to check email settings with godaddy technical support.
  2. You have to use the following relay server as the mail server: relay-hosting.secureserver.net
  3. You do not need to provide any user name & password for this relay server but you need an valid from email address. You have to use default credentials:smtp.UseDefaultCredentials = true; 
  4. You have to turn off ssl connection as it does not support secure connection: smtp.EnableSsl = false;
asp.net web.config file settings:
<appSettings>
    <!–email hosting for godaddy website–>
    <add key=MailServer value=relay-hosting.secureserver.net/>
    <add key=Port value=25/>
    <!–godaddy hosting does not need username & password–>
    <!–
    –>
    <add key=FromMail value=masuds_mail@yahoo.com/>
    <add key=SendToMail value=info@ete-consulting.co.uk />
  </appSettings>
 
  <system.web>
    <!–custome error mode need to be off or remote only–>
    <customErrors mode=Off/>
    <!–asp.net c# web application shows error:
    The application attempted to perform an operation not allowed by the security policy. 
    To grant this application the required permission please contact your system administrator or
    change the application’s trust level in the configuration file. –>
    <trust level=Full originUrl=“”/>
   

config.cs class file:
public static string SendMail(string subject, string body)
    {
        //function: send html email using asp.net c#
        SmtpClient smtp = new SmtpClient();
        smtp.Host = Config.MailServer;
        smtp.Port = Config.Port;
        //credentials need to set to true for godaddy hosting
        smtp.UseDefaultCredentials = true;
        //godaddy does not support Secure connection
        smtp.EnableSsl = false;
        //smtp.Credentials = new System.Net.NetworkCredential(Config.UserName, Config.Password);
        MailMessage mailMsg = new MailMessage();
        mailMsg.To.Add(Config.SendToMail);
        mailMsg.From = new MailAddress(Config.FromMail);
        mailMsg.Subject = subject;
        mailMsg.Body = body;
        //send html email message.
        //you will be able to use html tag in the message to
        mailMsg.IsBodyHtml = true;
        string msg = null;
        try
        {
            smtp.Send(mailMsg);
        }
        catch (Exception ex)
        {
            msg = ex.Message;
            //throw ex;
        }
        return msg;
    }
aspx.cs coding to send email html formatted
protected void btnStartProject_Click(object sender, EventArgs e)
    {
        //in order to be able to see the html elements in aspx.cs use the runat=”server” attribute
        string message, subject, body, name, gender;
        subject = slProjectType.Value;
        name = firstName.Value + ” “ + lastName.Value;
        if (male.Checked == true)
            gender = “Male”;
        else
            gender = “Female”;
       
       
        body =

Dear sir,

            +

I am interested to start a “

            + slProjectType.Value
            + ” with your company http://www.ete-consulting.co.uk

            +

My personal details:

            +

First name: “

            + firstName.Value
            +

Last name: “

            + lastName.Value
            +

Gender: “

            + gender
            +

My country: “

            + slCountrySelector.Value
            +

My contact details

            +

mobile: “

            + telephone.Value
            +

email: “

            + email.Value
            +

Project details

            +

Project type: “

            + slProjectType.Value
            +

Here is my project details (Message from the customer): “

            + txtProjectBrief.Value
            +

Thank you

            + name
            ;
        //call the email function
        message = Config.SendMail(subject, body);
       
        if (message == null)
            lblMessage.InnerText = “Email sent succefully.”;
        else
            lblMessage.InnerText = “Sorry, your email was not sent to the sender. Please try again.”;
       
        //show the email successfull message
        lblMessage.InnerHtml = message;
    }
Troubleshoot godaddy website error messages
If the MailServer host name is wrong it shows error:
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 202.xx.xx.xx:80
If the user credentials are used, it shows error:
the remote certificate is invalid according to the validation procedure
If EnableSsl is used it shows error:
server does not support secure connection
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s