I have a form on a MVC Web Application that is hosted over at GoDaddy that users can fill out and send to our office. I am currently testing it using both a Gmail account and a GoDaddy email account (linked to my hosting space). With the Gmail code in place, the email will send fine from my localhost, but when I publish it to the web I get the following error:
我在GoDaddy上托管的MVC Web应用程序上有一个表单,用户可以填写并发送到我们的办公室。我目前正在使用Gmail帐户和GoDaddy电子邮件帐户(链接到我的托管空间)对其进行测试。有了Gmail代码,电子邮件将从我的本地主机发送,但当我将其发布到网络时,我收到以下错误:
Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
请求类型'System.Net.Mail.SmtpPermission,System,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的权限失败。
Here is the code (borrowed from this post) I am using, credentials have been changed and password removed:
以下是我正在使用的代码(借用此帖子),凭据已更改并删除了密码:
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);
}
I then tried to use my GoDaddy email that I set up for this particular form, and again locally it sends. However, when this one is uploaded it just times out rather than give me any sort of useful information. Here is that code:
然后我尝试使用我为此特定表单设置的GoDaddy电子邮件,并再次在本地发送。但是,当这个上传时,它只是超时而不是给我任何有用的信息。这是代码:
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);
}
Originally I had smtpout.secureserver.net
for my GoDaddy Host, but I found out from this article that I needed to change it to relay-hosting.secureserver.net
. With the updated host information, the script runs but the mail message does not make it to the destination email inbox (or spam box).
最初我的GoDaddy主机有smtpout.secureserver.net,但我从这篇文章中发现我需要将它更改为relay-hosting.secureserver.net。使用更新的主机信息,脚本将运行,但邮件消息不会进入目标电子邮件收件箱(或垃圾邮件箱)。
Edit
Using Maxim's code, it seems I have gotten a "functioning" version in place. The email does not immediately appear in the destination inbox, but does so after about 15 minutes. Too bad it seems that GoDaddy is a giant PITA when it comes to programmatic emailing.
使用Maxim的代码,似乎我已经获得了一个“正常运行”的版本。电子邮件不会立即显示在目标收件箱中,但会在大约15分钟后显示。太糟糕了,GoDaddy在程序化电子邮件方面似乎是一个巨大的PITA。
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 the assistance, I hope that I can figure out how to get GoDaddy to cooperate better. If I can, I will post back with updates.
再次感谢您的帮助,我希望我能弄清楚如何让GoDaddy更好地合作。如果可以的话,我会回复更新。
4 个解决方案
#1
7
I have some ASP.NET MVC applications hosted on GoDaddy, too, that send out email. Unfortunately, the GoDaddy email policy is somewhat bad:
我在GoDaddy上托管了一些ASP.NET MVC应用程序,它们发送电子邮件。不幸的是,GoDaddy电子邮件政策有些不好:
First of all, you must use relay-hosting.secureserver.net
- you cannot use external SMTP servers, like Gmail.
首先,您必须使用relay-hosting.secureserver.net - 您不能使用外部SMTP服务器,如Gmail。
Secondly, relay-hosting
is usually very very slow. In my experience, some emails take around 90 minutes to be sent out, while others simply aren't delivered at all.
其次,中继托管通常非常慢。根据我的经验,一些电子邮件大约需要90分钟发送,而其他电子邮件则根本没有发送。
I've emailed back and forth with GoDaddy support many times about this issue but they have yet to fix the huge wait times/problems or allow external SMTP servers.
我已经多次通过GoDaddy支持来回发送有关此问题的电子邮件,但他们尚未解决巨大的等待时间/问题或允许外部SMTP服务器。
As for why your messages aren't delivering, you should try running the script multiple times to make sure that no anomalies are occuring. If it still doesn't work, here's my mail 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 have noticed) is that you are trying to supply credentials to the SMTP server. Actually, relay-hosting.secureserver.net
does not require any credentials whatsoever, but it will only send email if it detects that the message is being sent from a GoDaddy server. This might fix your problem!
唯一不同的是(据我所知),您正在尝试向SMTP服务器提供凭据。实际上,relay-hosting.secureserver.net不需要任何凭据,但只有在检测到消息是从GoDaddy服务器发送时才会发送电子邮件。这可能会解决您的问题!
#2
3
I received this error: "Mailbox name not allowed. The server response was: sorry, relaying denied from your location". I was using 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);
Upon reviewing this answer: https://*.com/a/4594338/1026459 I came to realize that the Host
should be different if using credientials. I changed my code to this:
在回答这个答案时:https://*.com/a/4594338/1026459我意识到如果使用信用证,主机应该是不同的。我将我的代码更改为:
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "smptout.secureserver.net";
//same code as above
And not only did the emails send properly, but they arrived in seconds.
不仅电子邮件发送正确,而且它们在几秒钟内到达。
#3
2
Don't recall where I found this code, but it works for me on my GoDaddy server for sending email via a google account:
不记得我在哪里找到了这个代码,但它在我的GoDaddy服务器上适用于通过谷歌帐户发送电子邮件:
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: Here is how I am using 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);
This may make a difference...I have a Google Apps account (free). Therefore, I am able to have the from address the same domain as my server.
这可能会有所不同......我有一个Google Apps帐户(免费)。因此,我可以使from地址与我的服务器相同的域。
#4
0
It works fine, follow my steps
它工作正常,按照我的步骤
-
First check your Email plan from Godaddy Webmail
首先从Godaddy Webmail检查您的电子邮件计划
a. Log in to your Account Manager.
一个。登录您的客户经理。
b. Click Workspace Email.
湾单击Workspace Email。
c. Next to the account you want to use, click Manage.
C。在要使用的帐户旁边,单击“管理”。
d. For the account with the email address you want to use, click (Show addresses).
d。对于包含您要使用的电子邮件地址的帐户,请单击(显示地址)。
e. Click the email address you want to use, and then go to the Advanced tab.it shows the Email Plan.
即单击要使用的电子邮件地址,然后转到“高级”选项卡。它显示电子邮件计划。
[1]: http://i.stack.imgur.com/AJAoB.png
Based on Email Plan, You choose the Host Name. Example: If Email Plan AP(2) means smtp.Host="smtpout.asia.secureserver.net"or if Email plan EU(2)means smtp.Host="smtpout.europe.secureserver.net" or if Email Plan US means smtp.Host="smtpout.secureserver.net".
根据电子邮件计划,您可以选择主机名。示例:如果电子邮件计划AP(2)表示smtp.Host =“smtpout.asia.secureserver.net”或电子邮件计划EU(2)表示smtp.Host =“smtpout.europe.secureserver.net”或电子邮件计划美国意思是smtp.Host =“smtpout.secureserver.net”。
-
Confirm your site is with SSL or without SSL. Because you choose the portNo based on SSLs Example : if Without SSL means smtp.EnableSsl = false Out going PortNo is 25, 80, 3535. In case If With SSL means mtp.EnableSsl = true Out going PortNo is 465.
确认您的网站使用SSL或不使用SSL。因为您选择基于SSL的portNo示例:如果没有SSL意味着smtp.EnableSsl = false Out out PortNo是25,80,3535。如果使用SSL意味着mtp.EnableSsl = true Out out PortNo是465。
These are all the main points to stay in mind to work in Godaddy mail configuration.
这些是在Godaddy邮件配置中工作的所有要点。
Below mention 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);}
#1
7
I have some ASP.NET MVC applications hosted on GoDaddy, too, that send out email. Unfortunately, the GoDaddy email policy is somewhat bad:
我在GoDaddy上托管了一些ASP.NET MVC应用程序,它们发送电子邮件。不幸的是,GoDaddy电子邮件政策有些不好:
First of all, you must use relay-hosting.secureserver.net
- you cannot use external SMTP servers, like Gmail.
首先,您必须使用relay-hosting.secureserver.net - 您不能使用外部SMTP服务器,如Gmail。
Secondly, relay-hosting
is usually very very slow. In my experience, some emails take around 90 minutes to be sent out, while others simply aren't delivered at all.
其次,中继托管通常非常慢。根据我的经验,一些电子邮件大约需要90分钟发送,而其他电子邮件则根本没有发送。
I've emailed back and forth with GoDaddy support many times about this issue but they have yet to fix the huge wait times/problems or allow external SMTP servers.
我已经多次通过GoDaddy支持来回发送有关此问题的电子邮件,但他们尚未解决巨大的等待时间/问题或允许外部SMTP服务器。
As for why your messages aren't delivering, you should try running the script multiple times to make sure that no anomalies are occuring. If it still doesn't work, here's my mail 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 have noticed) is that you are trying to supply credentials to the SMTP server. Actually, relay-hosting.secureserver.net
does not require any credentials whatsoever, but it will only send email if it detects that the message is being sent from a GoDaddy server. This might fix your problem!
唯一不同的是(据我所知),您正在尝试向SMTP服务器提供凭据。实际上,relay-hosting.secureserver.net不需要任何凭据,但只有在检测到消息是从GoDaddy服务器发送时才会发送电子邮件。这可能会解决您的问题!
#2
3
I received this error: "Mailbox name not allowed. The server response was: sorry, relaying denied from your location". I was using 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);
Upon reviewing this answer: https://*.com/a/4594338/1026459 I came to realize that the Host
should be different if using credientials. I changed my code to this:
在回答这个答案时:https://*.com/a/4594338/1026459我意识到如果使用信用证,主机应该是不同的。我将我的代码更改为:
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "smptout.secureserver.net";
//same code as above
And not only did the emails send properly, but they arrived in seconds.
不仅电子邮件发送正确,而且它们在几秒钟内到达。
#3
2
Don't recall where I found this code, but it works for me on my GoDaddy server for sending email via a google account:
不记得我在哪里找到了这个代码,但它在我的GoDaddy服务器上适用于通过谷歌帐户发送电子邮件:
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: Here is how I am using 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);
This may make a difference...I have a Google Apps account (free). Therefore, I am able to have the from address the same domain as my server.
这可能会有所不同......我有一个Google Apps帐户(免费)。因此,我可以使from地址与我的服务器相同的域。
#4
0
It works fine, follow my steps
它工作正常,按照我的步骤
-
First check your Email plan from Godaddy Webmail
首先从Godaddy Webmail检查您的电子邮件计划
a. Log in to your Account Manager.
一个。登录您的客户经理。
b. Click Workspace Email.
湾单击Workspace Email。
c. Next to the account you want to use, click Manage.
C。在要使用的帐户旁边,单击“管理”。
d. For the account with the email address you want to use, click (Show addresses).
d。对于包含您要使用的电子邮件地址的帐户,请单击(显示地址)。
e. Click the email address you want to use, and then go to the Advanced tab.it shows the Email Plan.
即单击要使用的电子邮件地址,然后转到“高级”选项卡。它显示电子邮件计划。
[1]: http://i.stack.imgur.com/AJAoB.png
Based on Email Plan, You choose the Host Name. Example: If Email Plan AP(2) means smtp.Host="smtpout.asia.secureserver.net"or if Email plan EU(2)means smtp.Host="smtpout.europe.secureserver.net" or if Email Plan US means smtp.Host="smtpout.secureserver.net".
根据电子邮件计划,您可以选择主机名。示例:如果电子邮件计划AP(2)表示smtp.Host =“smtpout.asia.secureserver.net”或电子邮件计划EU(2)表示smtp.Host =“smtpout.europe.secureserver.net”或电子邮件计划美国意思是smtp.Host =“smtpout.secureserver.net”。
-
Confirm your site is with SSL or without SSL. Because you choose the portNo based on SSLs Example : if Without SSL means smtp.EnableSsl = false Out going PortNo is 25, 80, 3535. In case If With SSL means mtp.EnableSsl = true Out going PortNo is 465.
确认您的网站使用SSL或不使用SSL。因为您选择基于SSL的portNo示例:如果没有SSL意味着smtp.EnableSsl = false Out out PortNo是25,80,3535。如果使用SSL意味着mtp.EnableSsl = true Out out PortNo是465。
These are all the main points to stay in mind to work in Godaddy mail configuration.
这些是在Godaddy邮件配置中工作的所有要点。
Below mention 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);}