[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.NET Send Email with GoDaddy Web Hosting

Posted on 2014-07-12
17
Medium Priority
?
5,146 Views
Last Modified: 2014-07-24
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

0
Comment
Question by:asp_net2
  • 7
  • 5
  • 4
16 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40192451
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
 
LVL 4

Author Comment

by:asp_net2
ID: 40192463
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
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40192473
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 4

Author Comment

by:asp_net2
ID: 40192485
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
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40192587
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
 
LVL 4

Author Comment

by:asp_net2
ID: 40192686
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
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40192754
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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 40193802
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
 
LVL 4

Author Comment

by:asp_net2
ID: 40203651
@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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 40203923
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
 
LVL 4

Author Comment

by:asp_net2
ID: 40204520
@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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 40208259
i'm still unclear. Why cant u just validate for to address and if its empty/invlaid then don't send the email?
0
 
LVL 4

Author Comment

by:asp_net2
ID: 40208676
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
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 2000 total points
ID: 40208688
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
 
LVL 4

Author Comment

by:asp_net2
ID: 40208782
Ok, now would I need to enter in that "if" statement the actual txtEmail.TextBox?
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 40208799
yes the to address would be the actual email address the user enters and bccaddress  will be the address of ur client
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question