9

I'm using EWS (Exchange Web Services) with Exchange 2010 to generate and send emails internally within our organization. We currently have a single mailbox/user for which all of our applications send through called app.

Generating emails is no problem, however when a test message is sent, it is received in the recipient's mailbox with the default account name in exchange, regardless of what display name is set in code.

Sample code:

EmailMessage message = new EmailMessage(ExchangeManager.CreateConnection());

// set from address as generic application account
message.From = new EmailAddress("app@company.com");

// set custom display name for sender email
message.From.Name = "Test Display Name";

// set send recipient as myself for testing
message.ToRecipients.Add(new EmailAddress("myaccount@company.com"));

ExchangeManager.SendExchangeMessage(message);

The message is received, however it displays as the app account's default name, rather than "Test Display Name" as used above in code. See screenshot of outlook inbox below:

Inbox View

This type of approach worked fine when using Exchange 2003 STMP services - we could format the address as needed, such as "Intranet Generated Mail ", or "Some Other Application ", etc. Now with Exchange 2010 and EWS it doesn't seem to allow us this option to use a custom display name.

I have also verified through debugging that the display name is being set successfully before the message is sent.

Has anyone successfully used a custom display name with EWS / Exchange 2010?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
KP.
  • 13,218
  • 3
  • 40
  • 60

2 Answers2

-2

(Talking in C# terms) Normally the method

EmailAddress()

has an overload where in you can specify the display name:

message.From = new EmailAddress("Custom Display Name", "app@company.com");

Try the above code & see.

  • 1
    I think this is equivalent to the method in de code sample in the question. Anyway, the "Custom Display Name" is not applied (tested with Exchange version 2015). – R. Schreurs Sep 28 '20 at 09:54
-4

I use EWS, but I've never had to set the Display name manually, because I configured it in Exchange beforehand. In other words, change the Display field of your "app" account in Exchange, and you won't need to manually set it in your program.

WEFX
  • 8,298
  • 8
  • 66
  • 102
  • Sorry this doesn't help - the point is we use this account for sending mail from many applications, and want to use a custom display name from each application. Setting it to a generic display name in exchange itself won't meet our needs - although perhaps as a last resort. It isn't ideal though as messages from all applications will sort the same in outlook, etc. – KP. May 14 '12 at 14:07
  • Since no other answers, I'll mark this as answer. We'll be using a common email address across all applications, and applying a application-specific prefix to each email subject as a work-around... – KP. May 17 '12 at 19:17
  • I agree that there does not seem to be any way to accomplish what you want via EWS. If you can send the emails through a SMTP server (which the Exchange 2010 hubs are, but may have a tight firewall on) then you can easily use a custom "From" header there to get what you want. – Elijah W. Gagne Jan 28 '13 at 18:49