ASP.NET Send Email with GoDaddy Web Hosting

Hello Experts,

I have an ASP.NET Web Form written in C# using SQL Server 2012.

My form includes questions and once the user clicks on the submit button it executes the code in SendEmail() which should email the user that entered the form information that I want them to see. However, when I try to submit the data on my local development end I get the following error below. The data still gets added to the database but I get the following error below. I'm going to attach my SendMail() code below the error.

Error that I receive:
System.Net.Mail.SmtpException: Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 173.201.192.229 (173.201.192.229:25), NB connect error 1460 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) at _Default.SendEmail() in c:\inetpub\wwwroot\TMF\Default.aspx.cs:line 449 at _Default.btnSubmitApplication_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\TMF\Default.aspx.cs:line 569

LVL 4
asp_net2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Have you checked to see if your ISP allows connections on port 25 to other services?  Many do not in order to limit spam from home computers.
0
asp_net2Author Commented:
Hi Dave,

I never thought about looking at those settings. So I looked at the settings in my iPhone and below is what I found. If I need to make these additions would be willing to modify my SendMail() Code with the changes?

iPhone Settings:

Outgoing Mail Server Settings:

smtpout.secureserver.net
Use SSL: On
Server Port: 465

Incoming Settings:

pop.secureserver.net
Use SSL: On
Server Port: 995
0
Dave BaldwinFixer of ProblemsCommented:
Those are for your own email address on your phone.  Are you using that same email address in that code above?  And is the ISP for your computer the same as the one for your phone?  Many times they are not the same and they do not have the same restrictions.  In particular, many ISPs block port 25 which your code above is using.  In addition, if you are going to use a 'secure' connection in your ASP code, you need to look up the additional settings required to do that.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

asp_net2Author Commented:
Hi Dave,

The information about the Mail Server settings are from GoDaddy which is who host's my website. So I'm assuming I would need to add those settings within the code or my web.config file to prevent the error message that I'm getting. I'm just not sure how or were to add those settings at with the SendMail() Code.
0
Dave BaldwinFixer of ProblemsCommented:
First, let me say that I have several Godaddy web hosting and email accounts that are set up and working fine.  My desktop email clients use the same ports and servers that you list above.  I also have code on my local web server on this computer that will connect to the Godaddy mail server on port 25 and send email.  

The same code on my other computer will not work because the ISP connection on that computer (Comcast) will not allow a connection to port 25.  Your code above shows an error connecting on port 25 (173.201.192.229:25).  That is why I keep asking you if your ISP for your "local development end" allows connections on port 25.  I am assuming that your "local development end" is on your home computer and not on your Godaddy web hosting.

In addition, the simple ASP code that works on my Godaddy web servers will not work on my local web servers because additional parameter are needed to connect to a remote web server.  Maybe some of the code on this page will help:  http://social.msdn.microsoft.com/Forums/en-US/b3c3b5c1-84fd-468b-9972-f108ee32c9b0/use-c-in-aspnet-to-perform-sending-email   And here is a page from Godaddy:  http://support.godaddy.com/help/article/1073/using-cdosys-to-send-email-from-your-windows-hosting-account   But I'm not sure it is complete for your needs.

While this page http://www.paulsadowski.com/wsh/cdo.htm is for VB, it shows some of the extra configuration required for different situations.
0
asp_net2Author Commented:
Hi Dave,

My ISP is Comcast as well. So I did some digging around on Google and I made some changes to my SendMail() Code below. Now when I run my code locally I get the following error message below.

Updated SendMail() Code:

    protected void SendEmail()
    {
        SmtpClient smtpClient = new SmtpClient();

        smtpClient.Host = "smtpout.secureserver.net";
        smtpClient.EnableSsl = true;
        smtpClient.Port = 465;
        smtpClient.Credentials = new System.Net.NetworkCredential("info@myaccount.com", "myaccountPassword");

        MailMessage message = new MailMessage();

        MailAddress fromAddress = new MailAddress("noreply@anotheraccount.org", "noreply@anotheraccount.org");
        MailAddress toAddress = new MailAddress(HttpUtility.HtmlEncode(txtEmail.Text));
        MailAddress bccAddress = new MailAddress("info@myaccount.com", "info@myaccount.com");

        message.From = fromAddress;
        message.To.Add(toAddress);
        message.Bcc.Add(bccAddress);

        message.Subject = "Financial Assistance Evaluation Form";
        message.IsBodyHtml = true;
        message.Body = "<html><head><title>" + "</title></head><body>" + "<h3>Thank you for contacting.</h3>" + "<p>We will review your application information as soon as possible.</p>" + "<p>If you do not hear back from us by phone, email or text within 2-3 days, please feel free to follow up.</p>" + "</body></html>";

        smtpClient.Send(message);
    }

Open in new window


Error Message:

System.Net.Mail.SmtpException: The operation has timed out. at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.SendEmail() in c:\inetpub\wwwroot\TMF\Default.aspx.cs:line 460 at _Default.btnSubmitApplication_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\TMF\Default.aspx.cs:line 580
0
Dave BaldwinFixer of ProblemsCommented:
That's better.  But at this point, you need to click on "Request Attention" to get others to look at your question because I can't help you anymore with the code that's left.
0
Gautham JanardhanCommented:
depending on the type of account you have go daddy may or may not let you mail from outside go daddy servers. In my case the code to send mail fails locally but works once its hosted. can you hosting your code and try once?


also you may want to look at how many relays you have left for this email id in godaddy panel
0
asp_net2Author Commented:
@Gautham Janardhan,

Ok, so I was able to get my email to work. However, I have a small issue now. On my web form I have a field called "Email Address" which is used for the user to enter his/her email address. When the form gets submitted a confirmation email will be sent to the email that was entered into this field. However, if a user does NOT enter an email address then I get an error about a valid email not getting entered which makes sense. Is there a way to still send the email out if the "Email" field is left empty?

    protected void SendEmail()
    {
        SmtpClient smtpClient = new SmtpClient();

        smtpClient.Host = "smtpout.secureserver.net";
        smtpClient.Credentials = new System.Net.NetworkCredential("info@mydomain.com", "EmailPassword");

        MailMessage message = new MailMessage();

        MailAddress fromAddress = new MailAddress("noreply@mydomain.org", "noreply@mydomain.org");
        MailAddress toAddress = new MailAddress(HttpUtility.HtmlEncode(txtEmail.Text));
        MailAddress bccAddress = new MailAddress("info@mydomain.com", "info@mydomain.com");

        message.From = fromAddress;
        message.To.Add(toAddress);
        message.Bcc.Add(bccAddress);

        message.Subject = "Form";
        message.IsBodyHtml = true;
        message.Body = "<html><head><title>" + "</title></head><body>" + "<h3>Test</h3>" + "<p>Test</p>" + "</body></html>";

        smtpClient.Send(message);
    }

Open in new window

0
Gautham JanardhanCommented:
do you mean fromAddress? i think thts needed when sending mail thru go daddy. Maybe you can use some dummy email address if the user doesn't enter one
0
asp_net2Author Commented:
@Gautham Ianardhan,

No, the fromAddress is fine. If you look at my code above you will see that I'm hard coding in an email address. The toAddress is what I'm having the issue with. The toAddress is bound to a TextBox Control on the web form called "txtEmail". If this field does not get added with a valid email address then that is when I get the error. If a user does enter a valide email into the TextBox "txtEmail" then everything works fine.
0
Gautham JanardhanCommented:
i'm still unclear. Why cant u just validate for to address and if its empty/invlaid then don't send the email?
0
asp_net2Author Commented:
I could but my client still wants an email to get generated if a user filling out the form does not have an email address. If a user does not have an email then he gets notified that an entry was just created.

If a user enters an email address then they receive a confirmation email along with my client.

So either way if the user filling out the form enters an email address or does not enter an email address my client still wants notified via email that an entry was just created.

As of now, if a user does not enter an email address in the txtEmail.Textbox then I get error and the form will not submit.
0
Gautham JanardhanCommented:
try something like this

if(string.isnullorempty(toAddress))
{
        message.To.Add(bccAddress);
}
else
{        
message.To.Add(toAddress);
message.Bcc.Add(bccAddress);
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
asp_net2Author Commented:
Ok, now would I need to enter in that "if" statement the actual txtEmail.TextBox?
0
Gautham JanardhanCommented:
yes the to address would be the actual email address the user enters and bccaddress  will be the address of ur client
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.