我在Godaddy上托管了一个ASP.NET应用程序,我希望从中发送电子邮件。当它运行时,我得到:不允许使用邮箱名称。服务器响应是:抱歉,从您的位置拒绝转发。代码的重要部分和Web.config如下:
msg = new MailMessage("accounts@greektools.net", email);
msg.Subject = "GreekTools Registration";
msg.Body =
"You have been invited by your organization to register for the GreekTools recruitment application.<br/><br/>" +
url + "<br/><br/>" +
"Sincerely,<br/>" +
"The GreekTools Team";
msg.IsBodyHtml = true;
client = new SmtpClient();
client.Host = "relay-hosting.secureserver.net";
client.Send(msg);
<system.net>
<mailSettings>
<smtp from="accounts@greektools.net">
<network host="relay-hosting.secureserver.net" port="25" userName="********" password="*********" />
</smtp>
</mailSettings>
答案 0 :(得分:19)
1-如果您的网站托管在godaddy上,您可以在没有凭据的情况下使用“relay-hosting.secureserver.net”。
2-如果您的网站是在godaddy之外托管的,您可以使用“smtpout.secureserver.net”与您的电子邮件帐户凭据。
PS:如果您遇到25
的问题,请更改3535端口托管GoDaddy
<system.net>
<mailSettings>
<smtp from="abc@xyz.net">
<network host="relay-hosting.secureserver.net"/>
</smtp>
</mailSettings>
</system.net>
外部
<system.net>
<mailSettings>
<smtp from="abc@xyz.net">
<network host="smtpout.secureserver.net"
userName="abc@xyz.net" password="your_password_here"
port="25" />
</smtp>
</mailSettings>
</system.net>
答案 1 :(得分:2)
这是我的电子邮件课程:
public class Email
{
public enum MailAddressType
{
From = 1,
Bcc
}
private static MailAddress _from = null;
public static void SendEmail(string to, string subject, string body)
{
SendEmail(to, subject, body, From, string.Empty);
}
public static void SendEmail(string to, string subject, string body, string from)
{
SendEmail(to, subject, body, from, MailAddressType.From);
}
public static void SendEmail(string to, string subject, string body, string addresses, MailAddressType addressType)
{
MailAddress from = From;
string bcc = string.Empty;
if (MailAddressType.From == addressType)
{
from = new MailAddress(addresses);
}
else
{
bcc = addresses;
}
SendEmail(to, subject, body, from, bcc);
}
private static void SendEmail(string to, string subject, string body, MailAddress from, string bcc)
{
MailMessage message = new MailMessage();
message.From = From;
message.To.Add(to);
if (!string.IsNullOrEmpty(bcc))
{
message.Bcc.Add(bcc);
}
message.ReplyTo = from;
message.Subject = subject;
message.Body = HttpContext.Current.Server.HtmlEncode(body);
SmtpClient smtp = new SmtpClient();
smtp.Send(message);
}
public static MailAddress From
{
get
{
if (null == _from)
{
SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
string address = section.From;
string displayName = ConfigurationManager.AppSettings["fromEmailDisplayName"];
_from = new MailAddress(address, displayName);
}
return _from;
}
}
}
以下是相关的web.config设置:
<appSettings>
<add key="fromEmailDisplayName" value="Firstname Lastname"/>
</appSettings>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="myname@mydomain.com">
<network host="relay-hosting.secureserver.net" />
</smtp>
</mailSettings>
</system.net>
对我来说,关键是“message.From = From”和“message.ReplyTo = from”。 GoDaddy似乎希望邮件来自您域中的地址。因此,对于联系人页面,请使用您的默认电子邮件地址作为发件人,并将发件人设置为ReplyTo。之后电子邮件会很好。
答案 2 :(得分:0)
这可能是来自SMTP服务器的回复,因为尝试发送电子邮件的计算机尚未列入白名单(或已列入垃圾邮件列入垃圾邮件)。 relay-hosting.secureserver.net是GoDaddy服务器,还是在不同的网络上?您可能想要找到一个允许中继电子邮件的GoDaddy服务器。我想今天很多共享托管服务提供商都有限制。
我会找出您正在使用的SMTP服务器类型以及适当的反垃圾邮件措施。管理员可以将GoDaddy服务器添加到允许的主机的白名单中。您需要非常小心,并确保您的应用程序不能用作垃圾邮件发送者的代理。确保验证所有输入以确保其安全。
答案 3 :(得分:0)
检查您的主机名。您确定您的帐户未配置为使用mail.greektools.net吗?这是GoDaddy虚拟主机的默认格式..
答案 4 :(得分:0)
设置
defaultCredentials="false"
在你的网络元素
中 <network host="relay-hosting.secureserver.net" port="25" userName="********" password="*********" defaultCredentials="false" />
答案 5 :(得分:0)
只是为了测试。从web.config中删除用户名和密码值。
然后,在您的代码集中
//call this line, before you call .Send
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(msg)
答案 6 :(得分:0)
我刚刚问GoDaddy,如何设置SMTP表单邮件,他们告诉我,我需要使用中继服务器,没有用户名,没有密码,也没有端口。要使用的服务器名称与您使用的名称相同。
答案 7 :(得分:0)
What email or relay server should I use in my ASP.NET 3.5 code?
您无需提供用户名 和中继服务器的密码。
答案 8 :(得分:0)
var message = new MailMessage();
message.To.Add(new MailAddress("email-address"));
message.From = new MailAddress("email-address");
message.Subject = "subject";
message.Body = string.Format("message-body");
message.IsBodyHtml = true;
using (var smtp = new SmtpClient())
{
smtp.Host = "relay-hosting.secureserver.net";
smtp.EnableSsl = false;
smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
await smtp.SendMailAsync(message);
}
答案 9 :(得分:0)
对于那些想知道除了接受的答案之外应该知道C#代码的人,下面的代码对我有用。请注意&#34;来自&#34;在接受的答案中已经在web.config中提到了地址,因此无需在C#代码中提及它。
public static void SendMail(string emailid, string subject, string body)
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(new MailAddress(emailid));
msg.Subject = subject;
msg.IsBodyHtml = true;
msg.Body = body;
client.Send(msg);
}
答案 10 :(得分:0)
尝试以下代码:
smtp.Host = "relay-hosting.secureserver.net";
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential("test@yourwebsitedomain.com", "*******");
对我有用。
答案 11 :(得分:0)
从C#代码发送Go Daddy电子邮件的代码对我有用
var smtp = new SmtpClient
{
Host = "smtpout.secureserver.net",
Port = 25,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("domain.xyz.com", "password...")
};
using (var message = new MailMessage("domain.xyz.com", "domain.xyz.com")
{
IsBodyHtml = false,
Subject = modal.Subject,
Body = modal.Body
})
{
smtp.Send(message);
}