How to send mail from Domain server in Asp.net c#?


How to send mail from Domain server in Asp.net c#?


Asked by:- RameshwarLate
1
: 447 At:- 12/15/2017 5:55:24 AM
asp c#






1 Answers
profileImage Answered by:- Sam

Sending mail from domain server is similar to sending emails using Gmail, just a difference is each domain uses a different port, different configuration, it should match your code, suppose your Email is on GoDaddy then using

host="relay-hosting.secureserver.net" port="25"

1- If your site is hosted on GoDaddy you may use "relay-hosting.secureserver.net" without credentials.

2- If your site is hosted outside of GoDaddy you may use "smtpout.secureserver.net" with your email account credentials.

Hosted On GoDaddy

    <system.net>
      <mailSettings>
       <smtp from="abc@xyz.net">
        <network host="relay-hosting.secureserver.net"/>
       </smtp>
      </mailSettings>
    </system.net>

External

  <system.net>
    <mailSettings>
      <smtp from="abc@xyz.net">
        <network host="smtpout.secureserver.net" 
           userName="abc@xyz.net" password="your_password_here" 
           port="25" />
      </smtp>
    </mailSettings>
  </system.net>

Complete asp.net C# Code (When it has Godaddy Email Hosting & the Website is Hosted on Godaddy, you can change port number and hosting as per your host)

using System;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e){}
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            //Create the msg object to be sent
            MailMessage msg = new MailMessage();

            //Add your email address to the recipients
            msg.To.Add("sam@gmail.net");

            //Configure the address we are sending the mail from
            MailAddress address = new MailAddress("info@domain.com");
            msg.From = address;
            msg.Subject = txtSubject.Text;
            msg.Body = txtName.Text + "n" + txtEmail.Text + "n" + txtMessage.Text;
 
    	    SmtpClient client = new SmtpClient();
    	    client.Host = "relay-hosting.secureserver.net";
    	    client.Port = 25;
 
            //Send the msg
            client.Send(msg);
 
            //Display some feedback to the user to let them know it was sent
            lblResult.Text = "Your message was sent!";
         }
        catch (Exception ex)
        {
            //If the message failed at some point, let the user know
            lblResult.Text = ex.ToString(); //alt text "Your message failed to send, please try again."
        }
    }
}

You may also need to look at the answer's provided here

https://qawithexperts.com/questions/152/how-to-send-mail-from-domain-server-in-aspnet-c

Article on sending email (which should work considering above comments)

https://qawithexperts.com/article/asp.net/send-email-using-c-mvc-net/16

If you are hosting on GoDaddy, here is the complete example (First part only)

http://vandelayweb.com/sending-asp-net-emails-godaddy-gmail-godaddy-hosted

Article, by GoDaddy itself https://in.godaddy.com/help/send-email-using-systemnetmail-19291

2
At:- 12/15/2017 7:55:02 AM Updated at:- 12/26/2017 2:01:55 PM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use