当我使用smpt.i发送邮件时得到error.system.exception:发送邮件失败。任何一个帮助。谢谢你 [英] When I send a mail using smpt.i got error.system.exception: failure sending mail.any one help.thank you

查看:154
本文介绍了当我使用smpt.i发送邮件时得到error.system.exception:发送邮件失败。任何一个帮助。谢谢你的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Page_Load(object sender,EventArgs e)

{

try

{

MailMessage message = new MailMessage();

message.To.Add(new MailAddress(receiverMailId));

message.From = new MailAddress(anwesh@gmail.com) ;

message.Subject =来自塔塔的信息;

message.Body =亲爱的用户,

+消息+

protected void Page_Load(object sender, EventArgs e)
{
try
{
MailMessage message = new MailMessage();
message.To.Add(new MailAddress(receiverMailId));
message.From = new MailAddress("anwesh@gmail.com");
message.Subject = "Information from Tata";
message.Body ="Dear User,

" + Message + "

问候,

+消息+

问候,

推荐答案

这是初学者在尝试发送电子邮件时必须面对的最基本错误。最常见的问题是:



1.主机名或协议不正确 - 这在您的代码中似乎不是问题。

2.用户名密码错误。必须检查哪一方。



重新检查这些并再试一次。基本上,您应该尝试使用已经过多次测试的工作代码示例。例如,尝试我编写的以下代码,

This the most basic error that beginners have to face while trying to send the email. The most common issues are:

1. Hostname or protocol not correct — which doesn't seem to be an issue over there in your code.
2. Username password error. Which must be checked on your side.

Re-check these and try again. Basically, you should try using a working code sample, that has been tested multiple times. For example, try the following code that I wrote,
// You should use a using statement
using (SmtpClient client = new SmtpClient("<smtp-server-address>", 25))
{
   // Configure the client
   client.EnableSsl = true;
   client.Credentials = new NetworkCredential("<username>", "<password>");
   // client.UseDefaultCredentials = true;

   // A client has been created, now you need to create a MailMessage object
   MailMessage message = new MailMessage(
                            "from@example.com", // From field
                            "to@example.com", // Recipient field
                            "Hello", // Subject of the email message
                            "World!" // Email message body
                         );

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

   /* 
    * Since I was using Console app, that is why I am able to use the Console
    * object, your framework would have different ones. 
    * There is actually no need for these following lines, you can ignore them
    * if you want to. SMTP protocol would still send the email of yours. */
    
   // Print a notification message
   Console.WriteLine("Email has been sent.");
   // Just for the sake of pausing the application
   Console.Read();
}



有关更多内容,我写了一篇文章,介绍了发送电子邮件的基本知识,以及如何解决过程中的一些错误,阅读它在这里,通过.NET框架发送电子邮件,以及一般问题 - 使用C#代码 [ ^ ]


这篇关于当我使用smpt.i发送邮件时得到error.system.exception:发送邮件失败。任何一个帮助。谢谢你的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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