I am sending a message using EXS as below. The code works fine and the email is successfully sent from the impersonated account. The problem is that the DisplayName property is not being shown in the received email. It appears to show the Active Directory username instead. What can I do to have the DisplayName property displayed in the receiving client.
image.png (22.8 KB)
IEWSClient client;
try
{
client = EWSClient.GetEWSClient(uri, exchangeusername, exchangepassword);
}
catch (Exception ex)
{
MessageBox.Show(string.Format(“Error Connecting to Exchange”, ex.Message), “Exchange Authentication”);
return;
}
Aspose.Email.License lic = new Aspose.Email.License();
//lic.SetLicense(Application.StartupPath + “\aspose.total.lic”);
MailMessage message = new MailMessage();
try
{
message.From = “tuser@afrm.com.au”;
message.From.DisplayName = “Test Name”;
client.ImpersonateUser(ItemChoice.PrimarySmtpAddress, message.From.Address);
}
catch (Exception ex)
{
MessageBox.Show(string.Format(“Error in eMail address”, ex.Message), “Test Exchange eMail”);
return;
}
try
{
message.To = "support@plannercrm.com.au";
}
catch { }
message.Subject = "Test eMail Message from AFRM";
try
{
client.Send(message);
MessageBox.Show(string.Format("eMail successfully passed to exchange to forward to '{0}'", message.To.ToString()), "Exchange Test eMail");
}
catch (Exception ex)
{
.Show(string.Format("Error sending eMail:\nFrom: {0}\nTo: {1}\nError: {2}", message.From, message.To[0], ex.Message), "Exchange Test eMail");
}
@ggnuttall,
It seems this is something related to Exchange server settings that are overriding the Display Name settings in the sent email using the API. We couldn’t find any such option to get this configured at the API end and this needs to be investigated more in Exchange Server configuration. Could you please ask your administrator about the permissions assigned to the impersonated user for the mailbox? This may be somehow related to these settings at your server.
Hi,
I discussed with the Exchange administrator and they are not aware of any setting that change this behaviour.
Can you shed any light of whether you are able to alter the display name on your test system?
@ggnuttall,
We lack required environment to test this issue further at our end. Unfortunately, we tried to impersonate two users on Office 365 test account, but couldn’t get success. We are currently setting up environment to test this behaviour at our end and it may take some time to achieve that. We’ll update you here as further information is available in this regard. Meanwhile, if you have test accounts that you can share with us for usage at our end or have guidelines about quick setup of impersonation in Office 365, you can share with us for our assistance.
Office 365 support gave me these commands to setup impersonation for a domain
set-executionpolicy unrestricted
$exchangesession = new-pssession -configurationname microsoft.exchange -connectionuri “[https://outlook.office365.com/powershell-liveid/ ](https://outlook.office365.com/powershell-liveid/)
” -credential $credential -authentication “basic” -allowredirection
import-pssession $exchangesession
New-ManagementRoleAssignment –name:impersonate1 –Role:ApplicationImpersonation –User:user@domain.onmicrosoft.com
Get-ManagementRoleAssignment impersonate1
Get-ManagementRoleAssignment impersonate1 | Format-List
@ggnuttall,
Is there any way we can do it from office 365 web login via admin page? We have two test accounts:
[UserOne@AsposeJun2018.onmicrosoft.com](mailto:UserOne@AsposeJun2018.onmicrosoft.com), Aspose1234
[UserTwo@AsposeJun2018.onmicrosoft.com](mailto:UserTwo@AsposeJun2018.onmicrosoft.com), Aspose1234
Sorry but we are not experts in Exchange server settings and that is why need a little assistance from your end in this regard.
Hi Team,
It would appear that it is not possible to achieve in this way according to Microsoft. Apparently you would need to write a Exchange Transport Account module to achieve it. Thus we are limited in display name only if sending via SMTP.
@ggnuttall,
Thank you for sharing this useful information. I assume that your query has been answered. Please feel free to write to us if you have any further query in this regard.