我在将电子邮件发送到非本地地址时遇到问题,例如:雅虎电子邮件,gmail等. [英] I have a problem in sending email to non-local address, say: yahoo email, gmail, etc.

查看:181
本文介绍了我在将电子邮件发送到非本地地址时遇到问题,例如:雅虎电子邮件,gmail等.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我有一个错误,
我已经编写了发送电子邮件的代码.
电子邮件已发送到私人电子邮件地址
像info@yourdomain.com

但是电子邮件没有发送给任何人
"gmail或yahoo邮件地址."

当我尝试向gmail或yahoo帐户发送电子邮件时,发生以下错误,

命令序列错误.服务器响应为:尝试发送到非本地电子邮件地址时,此邮件服务器需要身份验证.请检查您的邮件客户端设置或与管理员联系以验证是否为该域或地址定义了此服务器."

这是我的代码:

 受保护的 无效 SendEmail()
{
 
SmtpClient smtpClient =  SmtpClient("  MailMessage();
//  ------用于电子邮件数据--------------- ------------------- 
Msg.To.Add(TxtEmail .Text .Trim());
Msg.From =  MailAddress(" );

Msg.IsBodyHtml =  true ;

//  ----获取最大的用户ID ----------------- ------------- 
字符串 strConnection = ConfigurationManager.ConnectionStrings ["  span>].ConnectionString;
SqlConnection MaxUserIdCon =  SqlConnection(strConnection);
MaxUserIdCon.Open();
字符串 StrMaxUserId = " ;
 
SqlCommand MaxUserIdComm =  SqlCommand(StrMaxUserId,MaxUserIdCon);
 
SqlDataAdapter MaxUserIdDa =  SqlDataAdapter(MaxUserIdComm);
 
DataSet MaxUserIdDs =  DataSet();
 

MaxUserIdDa.Fill(MaxUserIdDs);
MaxUserIdCon.Close();
 
 int  MaxUserId =  1 ;
如果(MaxUserIdDs.Tables [ 0 ].Rows.Count> 0)
{
MaxUserId = Convert.ToInt32(MaxUserIdDs.Tables [ 0 ].rows [ 0 ] [" ].ToString());
}
//  ------------------------ ------------------------ 
 
StringBuilder bodyMsg =  StringBuilder();
 
bodyMsg.Append(" );
bodyMsg.Append(" );
 
Msg.Body = bodyMsg.ToString();
 
// 身份验证----------------------- -------------------------------------------------- ------- 
SmtpClient mySmtpClient =  SmtpClient();
System.Net.NetworkCredential myCredential =  System.Net.NetworkCredential(" " );
mySmtpClient.Host = " ;
mySmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mySmtpClient.UseDefaultCredentials =  false ;
mySmtpClient.Credentials = myCredential;

//  ------------------------ -------------------------------------------------- ----------------- 
mySmtpClient.Send(Msg);
LblMessage.Text = " ;
EmptyTextBoxes();

//  ------用于电子邮件数据-------------- ------------------- 
} 

解决方案

请不要在多个论坛中发布相同的问题;您已经在这里此处有此问题 [ ^ ].

[edit]
这是您第二次将其发布在问题与解答"中.
[/edit]


hi i have an error,
i have written a code to send an email.
the email was sent to private email address
like info@yourdomain.com

but the email was not sent to any
"gmail or yahoo mail address."

when i tried to sent an email to gmail or yahoo account the following error occurs,

"Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server."

here is my code :

protected void SendEmail()
{
 
SmtpClient smtpClient = new SmtpClient("mail.mydomain.com", 25);
MailMessage Msg = new MailMessage();
//------for Email Data----------------------------------
Msg.To.Add(TxtEmail .Text .Trim ());
Msg.From = new MailAddress("tehnical@mydomain.com");

Msg.IsBodyHtml = true;

//----Get Max userid------------------------------
string strConnection = ConfigurationManager.ConnectionStrings["AIGamesConnectionString"].ConnectionString;
SqlConnection MaxUserIdCon = new SqlConnection(strConnection);
MaxUserIdCon.Open();
string StrMaxUserId = "select max(id) as Id from users";
 
SqlCommand MaxUserIdComm = new SqlCommand(StrMaxUserId, MaxUserIdCon);
 
SqlDataAdapter MaxUserIdDa = new SqlDataAdapter(MaxUserIdComm);
 
DataSet MaxUserIdDs = new DataSet();
 

MaxUserIdDa.Fill(MaxUserIdDs);
MaxUserIdCon.Close();
 
int MaxUserId=1;
if (MaxUserIdDs.Tables [0].Rows.Count >0)
{
MaxUserId = Convert.ToInt32(MaxUserIdDs.Tables [0].Rows [0]["Id"].ToString ());
}
//------------------------------------------------
 
StringBuilder bodyMsg = new StringBuilder();
 
bodyMsg.Append("Thank you for creating your account.\n\nPlease follow this link to activate: ");
bodyMsg.Append("

Activate Your Account");
 
Msg.Body = bodyMsg.ToString();
 
//authentication--------------------------------------------------------------------------------
SmtpClient mySmtpClient = new SmtpClient();
System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("tehnical@mydomain.com", "password");
mySmtpClient.Host = "mail.mydomain.com";
mySmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mySmtpClient.UseDefaultCredentials = false;
mySmtpClient.Credentials = myCredential;

//-------------------------------------------------------------------------------------------
mySmtpClient.Send(Msg);
LblMessage.Text = "An email for account verification has been sent,please check your email";
EmptyTextBoxes();

// ------for Email Data----------------------------------
}

解决方案

Please do not post the same question in multiple forums; you already have this question here[^].

[edit]
And this is the second time you have posted it in Q&A.
[/edit]


这篇关于我在将电子邮件发送到非本地地址时遇到问题,例如:雅虎电子邮件,gmail等.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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