cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Go to solution

Using GoDaddy Provided Office365 Email for ASP.NET Contact Form

Hello,

I am trying to add a web form that takes an input and sends an email from a godaddy-provided office365 email account to my personal email. I am building this in asp.net using Visual Studio 2017. I have been able to get it to publish onto my website and be live, but it gives me the following exception when I fill out the form and try to submit it:

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 40.97.162.146:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at ShootingStarsEvent.contact.btnSend_Click(Object sender, EventArgs e) in D:\OneDrive\Projects\ShootingStarsEvent\ShootingStarsEvent\ShootingStarsEvent\contact.aspx.cs:line 132

I have the following section in my web.config file:

    <mailSettings>
      <smtp from="human@shootingstarsevent.com">
        <network host="relay-hosting.secureserver.net" port="25" />
      </smtp>
    </mailSettings>

and here is the code that is supposed to send the email. It works when I run this code locally, but it fails when it is actually present on the godaddy server.

            MailMessage msg = new MailMessage();
            msg.To.Add("human@shootingstarsevent.com");
            msg.To.Add("MY PERSONAL EMAIL");
            MailAddress address = new MailAddress("human@shootingstarsevent.com");
            msg.From = address;
            msg.Subject = "Contact Requested From " + tBoxName.Text;
            msg.Body = "Reply Back To " + tBoxEmail.Text + "\n\n\nMessage: " + tBoxMessage.Text;

            SmtpClient client = new SmtpClient();
            client.Host = "smtp.office365.com";
            client.Port = 25;
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            
NetworkCredential credentials = new NetworkCredential("human@shootingstarsevent.com", "MY PASSWORD", "shootingstarsevent.com");
            client.Credentials = credentials;

            //Send the msg
            try
            {
                client.Send(msg);
                lblResult.Text = "Message Successfully Sent!";
                tBoxName.Text = "";
                tBoxMessage.Text = "";
                tBoxEmail.Text = "";
            }
            catch (Exception ex)
            {
                lblResult.Text = ex.ToString();
                tBoxName.Text = "";
                tBoxMessage.Text = "";
                tBoxEmail.Text = "";
            }

 

Do any of you have any ideas what I could do to get this working?

4 REPLIES 4
Moderator
Moderator

Re: Using GoDaddy Provided Office365 Email for ASP.NET Contact Form

Hi @SamOhrenberg,

 

Thank you for posting. I moved your post to our "Building and Managing a Website" forum to give it more visibility.

Lisi - GoDaddy | Community Moderator
24/7 support available at x.co/247support

Re: Using GoDaddy Provided Office365 Email for ASP.NET Contact Form

Did you ever get your smtpclient code to work

Solution

Re: Using GoDaddy Provided Office365 Email for ASP.NET Contact Form

Got this working with the following settings:

SmtpClient client = new SmtpClient {

   Host = "smtp.office365.com",

   Credentials = new NetworkCredential("<FULL USERNAME@DOMAIN.COM", ConfigurationManager.AppSettings["password"]),

   Port = 587,

   EnableSsl = true,

   Timeout = 10000

};

Community Manager
Community Manager

Re: Using GoDaddy Provided Office365 Email for ASP.NET Contact Form

Thanks so much for sharing @hvaughan3! This is super helpful to others who may experience the same issue in the future. Take care!

Rachel