[英]Setting different From address for mail send through Office 365
While sending mail using office 365 how can we set different from address. 在使用Office 365发送邮件时,我们如何设置与地址不同的地址。 Basically the credentials I am giving are for office 365 account/username and from email address I am mentioning the different account. 基本上,我提供的凭据是针对Office 365帐户/用户名的,从电子邮件地址中我提到的是其他帐户。 So this has to be same? 所以这必须一样吗?
Below is my code. 下面是我的代码。
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("toid@domain.com", "To Name"));
msg.From = new MailAddress("fromid@domain.com", "From Name");
msg.Subject = "Azure Web App Email using smtp.office365.com";
msg.Body = "Test message using smtp.office365.com on Azure from a Web App";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("o365id@domain.com", "O365 PASS");
client.Port = 587;
client.Host = "smtp.office365.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
But it is giving me below error, 但这给了我下面的错误,
Mailbox unavailable. 信箱不可用。 The server response was: 5.7.60 SMTP; 服务器响应为:5.7.60 SMTP; Client does not have permissions to send as this sender 客户端无权发送此发送者
Basically I want to set the different from address while sending the mail. 基本上,我想在发送邮件时设置与地址不同的地址。
EDIT 1 : The from email address will be the logged in users email id. 编辑1 :发件人电子邮件地址将是登录用户的电子邮件ID。 This will be from same domain, but can we give the send as permission for common mailbox considering this. 这将来自相同的域,但是考虑到这一点,我们可以为普通邮箱授予“发送为”权限。
That error mean the credentials your trying to send with doesn't have the SendAS permission for the user/mailbox your trying to send as the Sender. 该错误意味着您尝试发送的凭据不具有您尝试作为发送方发送的用户/邮箱的SendAS权限。 To fix that you will either need to grant that through the Portal https://technet.microsoft.com/en-AU/library/jj919240%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396 or using PowerShell 要解决此问题,您将需要通过门户网站https://technet.microsoft.com/zh-CN/library/jj919240%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396授予该权限或
Add-ADPermission -Identity helpdesksupport -User o365id@domain.com -ExtendedRights "Send As"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.