Error sending email from ASP.NET MVC application hosted on GoDaddy

I have a form in an MVC web application hosted on GoDaddy that users can fill out and submit to our office. I am currently testing it using both a Gmail account and a GoDaddy email account (associated with my hosting). With a Gmail code in place, the letter will send a fine from my local host, but when I publish it on the Internet, I get the following error:

A permission request of type 'System.Net.Mail.SmtpPermission, System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' failed.

Here is the code (borrowed from this post ) I use, the credentials have been changed and the password has been deleted:

var fromAddress = new MailAddress(" iihs.eval@gmail.com ", "FEA Drone"); var toAddress = new MailAddress(" improveithomeservices@gmail.com ", "ImproveIt Home Services"); const string fromPassword = "<removed>"; var subject = string.Format("Energy Evaluation Request for {0} {1}", model.FirstName, model.LastName); var body = MailBody(results); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } 

Then I tried using the GoDaddy email that I configured for this particular form, and again it sends locally. However, when it loads, it just occasionally does not give me any useful information. Here is this code:

 var fromAddress = new MailAddress(" fea@goimproveit.com ", "FEA Drone"); var toAddress = new MailAddress(" improveithomeservices@gmail.com ", "ImproveIt! Home Services"); const string fromPassword = "<removed>"; var client = new SmtpClient { Host = "relay-hosting.secureserver.net", Port = 25, EnableSsl = false, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Timeout = 20000, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var msg = new MailMessage(fromAddress, toAddress) { Subject = string.Format("Energy Evaluation Request for {0} {1}", model.FirstName, model.LastName), IsBodyHtml = false, Body = MailBody(results) }) { client.Send(msg); } 

I initially had smtpout.secureserver.net for my GoDaddy host, but I learned from this article that I needed to change it to relay-hosting.secureserver.net . A script is executed with the updated host information, but the mail message does not get into the inbox of e-mail messages (or spam box).

Edit

Using the Maxim code, it seems that I got a β€œlive” version in place. The letter does not immediately appear in the destination folder, but does so after about 15 minutes. Too bad, GoDaddy seems to be a gigantic PITA when it comes to software-based emailing.

Here is what I got:

 var emailmessage = new System.Web.Mail.MailMessage() { Subject = subject, Body = body, From = fromAddress.Address, To = toAddress.Address, BodyFormat = MailFormat.Text, Priority = System.Web.Mail.MailPriority.High }; SmtpMail.SmtpServer = "relay-hosting.secureserver.net"; SmtpMail.Send(emailmessage); 

Thanks again for your help, I hope I can figure out how to get GoDaddy to work better. If I can, I will send an update message.

+6
asp.net-mvc smtp
source share
4 answers

I have ASP.NET MVC applications hosted on GoDaddy that send email. Unfortunately, GoDaddy's email policy is somewhat bad:

First of all, you should use relay-hosting.secureserver.net - you cannot use external SMTP servers, for example Gmail.

Secondly, relay-hosting usually very slow . In my experience, some emails take 90 minutes to send, while others simply don't arrive at all .

I have repeatedly emailed GoDaddy-enabled email about this issue, but they still have to fix the huge wait / problem times or resolve external SMTP servers.


As to why your messages are not being delivered, you should try running the script several times to make sure no anomalies occur. If it still doesn't work, here is my zip code:

 var emailmessage = new System.Web.Mail.MailMessage() { Subject = "Subject", Body = "Body", From = " myFromAddress@domain.com ", To = " myToAddress@someotherdomain.com ", BodyFormat = MailFormat.Text, Priority = MailPriority.High }; SmtpMail.SmtpServer = "relay-hosting.secureserver.net"; SmtpMail.Send(emailmessage); 

The only thing that is different (as far as I noticed) is that you are trying to provide credentials to an SMTP server. In fact, relay-hosting.secureserver.net does not require any credentials at all , but it will only send email if it detects that a message is being sent from the GoDaddy server. This may solve your problem!

+7
source share

I got this error: "The mailbox name is not resolved. Server response: sorry, relay denied from your location." I used this to connect:

 SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = "relay-hosting.secureserver.net"; smtpClient.Port = 25; smtpClient.Timeout = 10000; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential("emailAddress", "password"); String bodyText = "Hello World"; MailMessage mailMessage = new MailMessage("fromEmail", "toEmail", "Subject", bodyText); mailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; smtpClient.Send(mailMessage); 

After considering this answer: fooobar.com/questions/857589 / ... I realized that Host must be different if you use credientials . I changed the code to this:

 SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = "smptout.secureserver.net"; //same code as above 

And not only did the mail send correctly, but they arrived in a few seconds.

+3
source share

I don’t remember where I found this code, but it works for me on my GoDaddy server to send email via google account:

 public class GmailService : IEmailService { private static int _port = 465; private readonly string _accountName; private readonly string _password; public GmailService(string accountName, string password) { _accountName = accountName; _password = password; } public void Send(string from, string to, string subject, string body, bool isHtml) { Send(from, to, subject, body, isHtml, null); } public void Send(string from, string to, string subject, string body, bool isHtml, string[] attachments) { System.Web.Mail.MailMessage mailMessage = new System.Web.Mail.MailMessage { From = from, To = to, Subject = subject, Body = body, BodyFormat = isHtml ? MailFormat.Html : MailFormat.Text }; // Add attachments if (attachments != null) { for (int i = 0; i < attachments.Length; i++) { mailMessage.Attachments.Add(new Attachment(attachments[i])); } } // Authenticate mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); // Username for gmail - email@domain.com for email for Google Apps mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", _accountName); // Password for gmail account mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", _password); // Google says to use 465 or 587. I don't get an answer on 587 and 465 works - YMMV mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", _port.ToString()); // STARTTLS mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", true); // assign outgoing gmail server SmtpMail.SmtpServer = "smtp.gmail.com"; SmtpMail.Send(mailMessage); } } 

Update: this is how I use this code:

 GmailService gmail = new GmailService(" do_not_reply@bobcravens.com ", "the_password"); const string from = "Email Service < do_not_reply@bobcravens.com >"; const string to = "my_email_address"; const string subject = "Contact Form"; string body = "your message"; gmail.Send(from, to, subject, body, false); 

It can make a difference ... I have a Google Apps account (free). Therefore, I can have an address from the same domain as my server.

+2
source share

It works great, follow my steps

  • First check your Godaddy Webmail email plan

    but. Log in to your account manager.

    b. Click Workspace Email.

    from. Next to the account you want to use, click Manage.

    e. For the account with the email address you want to use, click (Show Addresses).

    e. Click the email address you want to use, and then click the "Advanced" tab. This shows the email plan.

    [1]: http://i.stack.imgur.com/AJAoB.png

    Based on your email plan, you choose a host name. Example: if the email address of AP (2) means smtp.Host = "smtpout.asia.secureserver.net" or if the email plan of the EU (2) means smtp.Host = "smtpout.europe.secureserver.net" or if Email Plan US means smtp.Host = "smtpout.secureserver.net".

  • Verify your site with SSL or without SSL. Because you choose SSL-based portNo Example: if Without SSL means smtp.EnableSsl = false PortNo exit is 25, 80, 3535. If If With SSL means mtp.EnableSsl = true PortNo exit is 465.

    These are all the key points to remember in order to work in the Godaddy mail configuration.

    Below is the code,

     using (MailMessage mail = new MailMessage(from, mailmodel.To)) { mail.Subject = mailmodel.Subject; mail.IsBodyHtml = true; mail.Body = mailmodel.Body; mail.Priority = MailPriority.High; SmtpClient smtp = new SmtpClient(); smtp.Host = host; smtp.EnableSsl = false; smtp.UseDefaultCredentials = false; NetworkCredential networkCredential = new NetworkCredential(from, Password); smtp.Credentials = networkCredential; smtp.Port = portNo; smtp.Timeout = 100000; smtp.Send(mail);} 
0
source share

All Articles