从 GoDaddy 上托管的 ASP.NET MVC 应用程序发送邮件消息的问题 [英] Issue sending mail message from ASP.NET MVC application hosted on GoDaddy

查看:29
本文介绍了从 GoDaddy 上托管的 ASP.NET MVC 应用程序发送邮件消息的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 GoDaddy 上托管的 MVC Web 应用程序上有一个表单,用户可以填写该表单并将其发送到我们的办公室.我目前正在使用 Gmail 帐户和 GoDaddy 电子邮件帐户(链接到我的托管空间)对其进行测试.使用 Gmail 代码后,电子邮件将从我的本地主机正常发送,但是当我将其发布到网络时,我收到以下错误:

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:

请求System.Net.Mail.SmtpPermission"类型的权限,系统,版本=2.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089' 失败.

Request for the permission 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 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);
}    

然后我尝试使用我为此特定表单设置的 GoDaddy 电子邮件,并再次在本地发送.然而,当这个上传时,它只是超时,而不是给我任何有用的信息.这是代码:

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:

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);
}

最初我有 smtpout.secureserver.net 用于我的 GoDaddy 主机,但我从 这篇文章 我需要把它改成 relay-hosting.secureserver.net.使用更新的主机信息,脚本会运行,但邮件不会到达目标电子邮件收件箱(或垃圾邮件箱).

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).

使用 Maxim 的代码,我似乎得到了一个正常运行"的版本.电子邮件不会立即出现在目标收件箱中,但会在大约 15 分钟后出现.太糟糕了,在程序化电子邮件方面,GoDaddy 似乎是一个巨大的 PITA.

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.

这是我得到的:

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);

再次感谢大家的帮助,希望能想办法让GoDaddy更好的配合.如果可以的话,我会发回更新.

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 上的 ASP.NET MVC 应用程序,它们会发送电子邮件.不幸的是,GoDaddy 电子邮件政策有些糟糕:

I have some ASP.NET MVC applications hosted on GoDaddy, too, that send out email. Unfortunately, the GoDaddy email policy is somewhat bad:

首先,您必须使用 relay-hosting.secureserver.net - 您不能使用外部 SMTP 服务器,例如 Gmail.

First of all, you must use relay-hosting.secureserver.net - you cannot use external SMTP servers, like Gmail.

其次,relay-hosting 通常非常慢.根据我的经验,有些电子邮件大约需要 90 分钟 才能发送出去,而其他的根本就没有送达.

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.

我已多次通过电子邮件向 GoDaddy 支持人员发送过有关此问题的电子邮件,但他们尚未解决巨大的等待时间/问题或允许外部 SMTP 服务器.

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.

至于为什么你的消息没有送达,你应该尝试多次运行脚本以确保没有异常发生.如果它仍然不起作用,这是我的邮件代码:

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);

唯一不同的(据我所知)是您尝试向 SMTP 服务器提供凭据.实际上,relay-hosting.secureserver.net 不需要任何凭据,但它只会在检测到邮件是从 GoDaddy 服务器发送时发送电子邮件.这可能会解决您的问题!

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!

这篇关于从 GoDaddy 上托管的 ASP.NET MVC 应用程序发送邮件消息的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆