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

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

问题描述

我有是在GoDaddy的托管在一个MVC Web应用程序,用户可以填写并邮寄到我们的办公室的形式。我使用的这两个Gmail帐户和GoDaddy的电子邮件帐户(链接到我的主机空间),目前正在测试它。有了Gmail的code,电子邮件将发送罚款从我的本地主机,但是当我把它发布到网上,我得到了以下错误:

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,文化=中立,
  公钥= b77a5c561934e089'失败。

Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

下面是code(从这篇文章<借/一>)我使用,证书已被更改密码删除:

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的邮件,我设置了这种特殊的形式,在本地再次发送。但是,当这个人是上传它只是超时,而不是给我任何类型的有用信息。下面是code:

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的code,看来我已经得到代替正常的版本。电子邮件没有立即出现在目标收件箱中,但约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.

第二, 继电器托管通常是非常非常慢。根据我的经验,有些邮件各地采取的以被发送出去,而别人根本不会在所有交付

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.

至于为什么你的消息不提供,你应该尝试运行脚本多次以确保没有异常现象存在的。如果仍然不能正常工作,这是我的邮件code:

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!

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

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