Emails from the store - "Friendly Display Name"

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 years ago
Would be nice to have a friendly name on outgoing emails from the store rather than just [email protected] emails can come through as:

"Your Store Sales Department" <[email protected]>

Patch below:

Changed Nop.Common/Messages/MessageManager.cs

Added new property "AdminEmailDisplayName"


        /// <summary>
        /// Gets or sets an admin email display name
        /// </summary>
        public static string AdminEmailDisplayName
        {
            get
            {
                return SettingManager.GetSettingValue("Email.AdminEmailDisplayName");
            }
            set
            {
                SettingManager.SetParam("Email.AdminEmailDisplayName", value.Trim());
            }
        }


Changed SendEmail method from:


message.From = new MailAddress(From);


to:


message.From = new MailAddress(From, AdminEmailDisplayName);


In Website Administration added new Setting:

Name: Email.AdminEmailDisplayName
Value: Yourstore Sales Department
Description: This is the email display name for outgoing emails

Reason:

Emails sent by application are sent from AdminEmailAddress only. Looks better to have a friendly display name i.e:
"Yourstore Sales Department" <[email protected]>

Other notes:

Ideally, SendEmail method (and underlying method0 should be changed from:


        public static void SendEmail(string Subject, string Body, string From, ICollection<string> To)
        {
            SendEmail(Subject, Body, From, To, new List<string>());
        }


to:


        public static void SendEmail(string Subject, string Body, MailAddress From, ICollection<string> To)
        {
            SendEmail(Subject, Body, From, To, new List<string>());
        }


Then when sending an email use the following:


SendEmail(subject, body, new MailAddress(AdminEmailAddress, AdminEmailDisplayName), to);


This way you have the option to exclude a display name or override the display name in individual methods.

NOTE: If implementing the second part of this patch (changing the constructor of SendEmail to accept a MailAddress object

instead of string), you will need to modify all calls to the SendEmail method, this includes those in CampaignManager.

You will need to import the System.Net.Mail namespace and change the calls to:

MessageManager.SendEmail(campaign.Subject, campaign.Body, new MailAddress(MessageManager.AdminEmailAddress, MessageManager.AdminEmailDisplayName), to);


**UPDATE**

You will need to do the same to Administration/CommonSettings.aspx.cs. Import system.net.mail namespace and modify SendEmail call. You may also want to take the opportunity to add a new text box to view/save the Display name setting (rather than having to do through etc. settings). You can look at how the other textboxes are loaded / saved if you are not sure how.

--------------------------------------------------------------------------------------------------------------
15 years ago
Thanks, Ben
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.