C# 在 GoDaddy 上通过 gmail SMTP 发送电子邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1225103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 13:52:59  来源:igfitidea点击:

Sending email through gmail SMTP on GoDaddy

c#.netsmtp

提问by

Is this possible? I am able to send through localhost, but on godaddy the email doesn't get sent. Has anyone managed to achieve this?

这可能吗?我可以通过本地主机发送,但是在godaddy 上没有发送电子邮件。有没有人设法实现这一目标?

I'm using C#

我正在使用 C#

回答by Reed Copsey

This seems to be a common issue.

这似乎是一个普遍的问题。

There are two things required.

有两件事需要。

  • Add a user that will be used for authentication. You can't send anonymously via GoDaddy
  • Follow the configuration specified here.
  • 添加将用于身份验证的用户。您无法通过 GoDaddy 匿名发送
  • 遵循此处指定的配置。

This should make it work correctly.

这应该使它正常工作。

回答by jkelley

It appears that GoDaddy blocks the SSL ports required by gmail's smtp access. This means you are out of luck at this point. You could just use GoDaddy's local relay:

GoDaddy 似乎阻止了 gmail 的 smtp 访问所需的 SSL 端口。这意味着您此时运气不佳。您可以使用 GoDaddy 的本地中继:

relay-hosting.secureserver.net with no credentials.

没有凭据的relay-hosting.secureserver.net。

http://help.godaddy.com/article/955

http://help.godaddy.com/article/955

回答by andersen

Almost forgot here are googles detailed instructions. The above tool will change automatically 8-)

差点忘了这里有谷歌的详细说明。以上工具会自动更改 8-)

http://www.google.com/support/a/bin/answer.py?hl=en&answer=33353

http://www.google.com/support/a/bin/answer.py?hl=zh-CN&answer=33353

回答by Ian

When using relay-hosting with Godaddy the email objects FROM email address MUST be a Godaddy "white Listed" email.

当使用 Godaddy 的中继托管时,来自电子邮件地址的电子邮件对象必须是 Godaddy 的“白名单”电子邮件。

They do this to stop spammers hiHymaning an account

他们这样做是为了阻止垃圾邮件发送者劫持帐户

There is an alternative for using the relay-host

有使用中继主机的替代方法

Using the GoDaddy form-mailer, (Google Serach: "_gdForm/webformmailer.asp")

使用 GoDaddy 表单邮件程序,(谷歌搜索:“_gdForm/webformmailer.asp”)

This alternative can be used to send a pre-designated "form-mailer" email account all the web forms and it does work! but does require some hosting.content.form-mailer setup on GoDaddy.

此替代方法可用于向所有 Web 表单发送预先指定的“表单邮件程序”电子邮件帐户,并且确实有效!但确实需要在 GoDaddy 上进行一些 hosts.content.form-mailer 设置。

check out how I've used the form-mailer:

看看我是如何使用 form-mailer 的:

(only catch is, it takes away the ability to code a subscribe/unsubscribe XML database, as the form data is sent off to this inaccessable ASP file) So I may end up revert back to using relay hosting in ASP.NET

(唯一的问题是,它剥夺了编写订阅/取消订阅 XML 数据库的能力,因为表单数据被发送到这个无法访问的 ASP 文件)所以我最终可能会恢复使用 ASP.NET 中的中继托管

www.earthed.net.au\News.aspx www.earthed.net.au\Contact.aspx www.earthed.net.au\Support.aspx

www.earthed.net.au\News.aspx www.earthed.net.au\Contact.aspx www.earthed.net.au\Support.aspx

My ultimate goal was to have an email come into my inbox from [email protected] with the necessry form field data, but no matter how you go your Host provider's security setting will ultimately determine your ability to do this.

我的最终目标是让一封电子邮件从 [email protected] 进入我的收件箱,其中包含必要的表单字段数据,但无论如何,您的主机提供商的安全设置将最终决定您执行此操作的能力。

Also tried using google and hotmail smtp hosts (as I have an account with each) and same secirty restriction story, maybe a lesser known free web email provider that has lower security settings allowing full relay hosting (if so let me know)

还尝试使用 google 和 hotmail smtp 主机(因为我每个都有一个帐户)和相同的安全限制故事,也许是一个鲜为人知的免费网络电子邮件提供商,其安全设置较低,允许完全中继托管(如果是这样,请告诉我)

回答by Mike

I think your best option is to find another host. When I was coding for a site on godaddy I remember asking godaddy whether they disabled their mapi functions and it turns out they do a little more than just disable it. I've heard they filter specific outgoing ports.

我认为你最好的选择是找到另一个主机。当我在 Godaddy 上为一个网站编码时,我记得问过 Godaddy 他们是否禁用了他们的 mapi 功能,结果他们做的不仅仅是禁用它。我听说他们过滤特定的传出端口。

回答by WD-40

The last time I tried doing this (maybe early 2011-ish) I was not able to programmatically send out from Gmail account on GoDaddy. I took code the exact same code that worked on a different hosting company's server and it failed on GoDaddy's server so I'm quite confident that the code was not the issue.

我上次尝试这样做时(可能是 2011 年初),我无法以编程方式从 GoDaddy 上的 Gmail 帐户发送邮件。我使用了与在不同托管公司的服务器上工作的完全相同的代码,但它在 GoDaddy 的服务器上失败了,所以我非常确信代码不是问题。

I called their tech support and got conflicting information but I had heard enough to convince myself sending via Gmail was not a for sure supported service on GoDaddy's servers.

我打电话给他们的技术支持并得到了相互矛盾的信息,但我听到的足够多的信息说服自己通过 Gmail 发送并不是 GoDaddy 服务器上肯定支持的服务。

I was also given the workaround option of using their web email form which is totally not what the project I was working on could use and underscored the notion that GoDaddy did not fully understand what they talking about.

我还获得了使用他们的网络电子邮件表单的解决方法选项,这完全不是我正在从事的项目可以使用的,并强调了 GoDaddy 没有完全理解他们在说什么的概念。

In the end I found that I was able to just use GoDaddy's SMTP servers and plug in my own "from" address which allowed me to send mail to any email address and to spoof the origination email address. So they end up locking down legitimate email functionality and instead force you to use a highly abusable system instead.

最后我发现我可以只使用 GoDaddy 的 SMTP 服务器并插入我自己的“发件人”地址,这允许我将邮件发送到任何电子邮件地址并欺骗原始电子邮件地址。因此,他们最终锁定了合法的电子邮件功能,而是强迫您改用高度可滥用的系统。

Again, this was a while ago that I ran into this issue but it would be easy enough to check to see if they still allow you to use their SMTP server to send emails.

同样,这是我不久前遇到这个问题的,但是很容易检查他们是否仍然允许您使用他们的 SMTP 服务器发送电子邮件。

回答by tryinHard

I am creating a simple contact form using ASP.Net MVC 3 on GoDaddy. I wanted to be able to send the emails to accounts hosted on Google Apps. This question matched my situation, but only this GoDaddy help articlereally solved my problem. Hope it helps someone else!

我正在使用 GoDaddy 上的 ASP.Net MVC 3 创建一个简单的联系表单。我希望能够将电子邮件发送到 Google Apps 上托管的帐户。这个问题符合我的情况,但只有这篇GoDaddy 帮助文章真正解决了我的问题。希望它可以帮助别人!

Code sample from the article:

文章中的代码示例:

    // language -- C#
// import namespace
using System.Web.Mail;

private void SendEmail()
{
   const string SERVER = "relay-hosting.secureserver.net";
   MailMessage oMail = new System.Web.Mail.MailMessage();
   oMail.From = "emailaddress@domainname";
   oMail.To = "emailaddress@domainname";
   oMail.Subject = "Test email subject";
   oMail.BodyFormat = MailFormat.Html; // enumeration
   oMail.Priority = MailPriority.High; // enumeration
   oMail.Body = "Sent at: " + DateTime.Now;
   SmtpMail.SmtpServer = SERVER;
   SmtpMail.Send(oMail);
   oMail = null; // free up resources
}

回答by Luis Perez

I was able to send an email through GoDaddy using these settings in the web.config:

我能够使用 web.config 中的这些设置通过 GoDaddy 发送电子邮件:

<configuration>
    <system.net>
        <mailSettings>
            <smtp>
                <network 
                    host="smtpout.secureserver.net" 
                    userName="[email protected]" 
                    password="****" />
                <!--
                As per @Yoro's comment you might have
                luck including the port number as well
                -->
            </smtp>
        </mailSettings>
    </system.net>
</configuration>

and this code:

和这个代码:

var SmtpClient = new SmtpClient();
SmtpClient.Send("[email protected]", "[email protected]", "subject", "body");

Note I believe that the from address in the email you are sending has to be from your domain. I tried sending an email as coming form another domain and got an error message.

请注意,我认为您发送的电子邮件中的发件人地址必须来自您的域。我尝试发送来自另一个域的电子邮件并收到一条错误消息。

You have to make sure you have an email account in GoDaddy, you can check by logging in and going to Products > Email > Email Plans. You also have to make sure SMTP relay is turned on, it was turned on by default for me. Also important to know by default my GoDaddy account only allows me to send 250 emails a day.

您必须确保您在 GoDaddy 中有一个电子邮件帐户,您可以通过登录并转到产品 > 电子邮件 > 电子邮件计划来进行检查。您还必须确保 SMTP 中继已打开,默认情况下它已为我打开。同样重要的是要知道默认情况下我的 GoDaddy 帐户只允许我每天发送 250 封电子邮件。

回答by Sulman Bin Khurshid

This Code works

此代码有效

// Create the msg object to be sent

MailMessage msg = new MailMessage();
// Add your email address to the recipients
msg.To.Add("[email protected]");
// Configure the address we are sending the mail from
MailAddress address = new MailAddress("[email protected]");
msg.From = address;
msg.Subject = txtSubject.Text;
msg.Body = txtName.Text + "n" + txtEmail.Text + "n" + txtMessage.Text;

SmtpClient client = new SmtpClient();
client.Host = "relay-hosting.secureserver.net";
client.Port = 25;

// Send the msg
client.Send(msg);

回答by user2965491

After experiencing the same issue you are describing in your question, I finally figure out a solution.

在遇到您在问题中描述的相同问题后,我终于找到了解决方案。

Check your web.config file and make sure that the debug property is set to false whenever you publish your website. Let me know if this works. It did for me.

检查您的 web.config 文件并确保在您发布网站时将调试属性设置为 false。让我知道这个是否奏效。它对我有用。

<configuration>
  <system.web>    
    <compilation debug="false" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <customErrors mode="Off"/>
  </system.web>      
</configuration>