正如我在标题中写的那样,我收到了一个错误:
5.7.62 SMTP;客户无权代表发件人地址发送
我想使用C#使用account2发送电子邮件,但好像它是account1。这意味着account2将发送电子邮件,但当收件人收到电子邮件时,他们会将account1视为发件人。
但如果我使用其他帐户(不是来自Office365)而不是使用account2(真正的发件人),则没有例外。
或者如果我使用其他帐户(不是来自Office365)而不是使用account1(显示发件人),则没有例外。
如果我发送foxmail客户端,一切都是正确的。
我试图在互联网上搜索问题几天,但仍然无法解决这个问题。你能给我一些建议吗?
我的代码:
static public void Send(string from, string fromDisplay, string fromPwd, string to, string toDisplayName)
{
//account1: an account from a office365 email server to (to display on the sender when received)
var emailFrom = new MailAddress("EmailToDisplayToReceiver@<theserver>.com", "test");
//account2:The sender is another account from an office365 email server(The real sender to send the email )
var sender = new System.Net.Mail.MailAddress(from, fromDisplay);
System.Net.Mail.MailAddress EmailTo = new System.Net.Mail.MailAddress(to, toDisplayName);
System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage(emailFrom, EmailTo);
Email.Sender = sender;
Email.Body = "The content";
Email.SubjectEncoding = System.Text.Encoding.Default;
Email.BodyEncoding = System.Text.Encoding.Default;
Email.IsBodyHtml = true;
Email.Priority = System.Net.Mail.MailPriority.High;
System.Net.Mail.SmtpClient SmtpPC = new System.Net.Mail.SmtpClient("smtp.office365.com", 587);
SmtpPC.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
SmtpPC.EnableSsl = true;
SmtpPC.UseDefaultCredentials=false;
//the real sender and password
SmtpPC.Credentials = new System.Net.NetworkCredential(from, fromPwd);
ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;
try
{
SmtpPC.Send(Email);
}
catch (Exception E)
{
//Here throwed an exception which said:
//Mailbox is unable to use.The server response is: 5.7.62 SMTP; Client does not have permissions to send on behalf of the from address
//(邮箱不可用。 服务器响应为: 5.7.62 SMTP; Client does not have permissions to send on behalf of the from address)
throw;
}
}
答案 0 :(得分:0)
这通常发生在发件人地址是假的或未在您尝试代表发送电子邮件的目录中定义的情况下。有几件事要尝试:
Send As
地址帐户提供正确的身份验证帐户On Behalf Of
/ From
权限。From
和Sender
使用相同的地址。sender
用户授予From
帐户权限。如果您需要更多信息,可以查看this链接,并阅读Use shell to assign permissions
部分。