[英]sending mail using asp.net
i am trying to send mails using c# in asp.net page on a free asp server. 我试图在免费的ASP服务器上的asp.net页中使用c#发送邮件。 i have wrote this code 我已经写了这段代码
public string send_email()
{
SmtpClient client = new SmtpClient("relay-hosting.secureserver.net", 25);
string to = "eng.mona.developer@gmail.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential("eng.mona.developer@gmail.com", "XXXXXXX");
MailAddress fromAddress = new MailAddress("mona.elsayed.shalaby@gmail.com", "Mona ");
MailMessage message = new MailMessage();
message.From = fromAddress;
message.To.Add(to);
message.Body = "This is Test message";
message.Subject = "hi";
client.Send(message);
message.Dispose();
return "Email Send";
}
and wrote this in web.config 并写在web.config
<mailSettings>
<smtp from="eng.mona.developer@gmail.com">
<network host="relay-hosting.secureserver.net" port="25" userName="eng.mona.developer@gmail.com" password="XXXXX"/>
</smtp>
</mailSettings>
but i have an error called 但是我有一个错误叫做
Mailbox name not allowed. 邮箱名称不允许。 The server response was: sorry, relaying denied from your location [XX.XXX.XX.XXX] (#5.7.1) 服务器响应为:很抱歉,您所在的位置[XX.XXX.XX.XXX](#5.7.1)拒绝中继
any help 任何帮助
It's a security error from your SMTP server, not your code's fault. 这是来自SMTP服务器的安全错误,而不是代码的错误。 Probably because you use your Gmail credentials to access a non-gmail SMTP server. 可能是因为您使用Gmail凭据访问了非Gmail SMTP服务器。
Make it so that you can allow anonymous emailing from your server where the page resides then you can set: 进行设置,以便可以允许从页面所在的服务器发送匿名电子邮件,然后可以进行以下设置:
client.UseDefaultCredentials = false;
and 和
message.From = "noreply@mydomain.com";
and like Max Al Farakh said, use the provided SMTP server which you have rights to. 就像Max Al Farakh所说的那样,使用您有权使用的提供的SMTP服务器。
1) If you use web.config <mailsettings>
configuration (and this is right!) you should not set SmtpClient
programmatically, or configuration will be useless! 1)如果使用web.config <mailsettings>
配置(这是对的!) ,则不应以编程方式设置SmtpClient
,否则配置将无用!
SmtpClient client = new SmtpClient();
MailMessage message = new MailMessage();
message.To.Add(to);
message.Body = "This is Test message";
message.Subject = "hi";`
this is enough, no server
o from
in code. 这就够了,没有server
Ø from
代码。
2) As Max's saying, this is not a code problem: this is a configuration problem ! 2)正如Max所说, 这不是代码问题:这是配置问题 ! Try a server-port-user-password configuration using your mail client (outlook, thunderbird or any other) and if this works you just have to copy it in tag. 尝试使用邮件客户端 (外观,雷鸟或任何其他客户端)配置服务器端口用户密码 ,如果可行,您只需将其复制到标记中即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.