A piece of code to set a specific sender name (eg: commercial name) with your emails


Right now, without this setting and to be more generic, I use the current site name directly in the code
var siteName = _orchardServices.WorkContext.CurrentSite.SiteName; // Evolutive
context.MailMessage.From = new MailAddress(smtpSettings.Address, siteName);


BertrandLeRoy wrote Nov 25, 2013 at 9:04 AM

This looks more like a question than an issue. Can you please explain exactly what you're asking?

jtkech wrote Nov 25, 2013 at 2:52 PM

Currently in the code, the MailAddress Constructor use only one parameter, the email address. It does not use the display name associated with this address (displayName)

This second parameter is useful, you can set it with a commercial name, and when someone receive an email he can see it in place of the email address

So, my suggestion was to add a new parameter for this property in the email settings (smtpSettings) on the dashboard

But today, I have seen in the MSDN doc that with only the first parameter you can add the display name to the email address, like that: "Tom Smith tsmith@contoso.com"

I have tried the same thing with my email address on the dashboard. And it works without Orchard code modification

Sorry for the inconvenience

jtkech wrote Nov 25, 2013 at 2:59 PM

Note : You have to enclose the email address in angle brackets. These was not dislayed in the previous comment

"DisplayName <emailAddress>"

sebastienros wrote Jul 1, 2014 at 9:00 PM

We already have some code somewhere to add cc/bcc and maybe the sender on the workflow tasks.

sebastienros wrote Jul 1, 2014 at 9:01 PM

And maybe also the code in the API to take these other parameters into account.

sebastienros wrote Jul 1, 2014 at 9:02 PM

Bertrand says it's in 1.8.1, let's check

agriffard wrote Feb 2 at 3:38 PM

Global settings have this field :
Sender email address
The default email address to use as a sender.

Can you confirm we can specify "DisplayName <emailAddress>" and if so, set the issue to Resolved ?

agriffard wrote Feb 2 at 4:39 PM

I modified my 'Sender email address' to "DisplayName myemail@hotmail.com" and configured the email settings to send with smtp.live.com by SSL with my account informations and made a contact form and a workflow activity that sends an email but the mail I receive doesn't have the DisplayName I specified.

jtkech wrote Feb 2 at 8:04 PM

It works for me on Azure Websites with Orchard 1.6.1 and with the "Sendgrid" service, and locally with an Orchard 1.8.x version and another smtp server + credentials but not SSL

If my "Sender email address" is "Evolutive <myemailAddress>", when I receive the email I can see the DisplayName "Evolutive"

But it would be handier to have a separate setting for the DisplayName. That said, it's not a concern for me because it works, so, for me, you can set this issue as resolved