im suggest should add this in next version: support DisplayName of email sender
Add 3 new function to DotNetNuke.Services.Mail.Mail
public static string ConvertEmailAddress(string Email, string DisplayName)
{
return string.Format("{0} <{1}>", DisplayName, Email);
}
public static string[] ExtractEmails(string str)
{
string RegexPattern = @"\b[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}\b";
// Find matches
System.Text.RegularExpressions.MatchCollection matches
= System.Text.RegularExpressions.Regex.Matches(str, RegexPattern,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
string[] MatchList = new string[matches.Count];
// add each match
int c = 0;
foreach (System.Text.RegularExpressions.Match match in matches)
{
MatchList[c] = match.ToString();
c++;
}
return MatchList;
}
public static MailAddress GetMailAddress(string EmailAddress)
{
var emails = ExtractEmails(EmailAddress);
if (emails.Length >= 1)
{
var displayName = "";
var emailAddress = "";
emailAddress = emails[emails.Length - 1];
//Get last email is primary
displayName = EmailAddress.Remove(EmailAddress.LastIndexOf(emailAddress));
displayName = displayName.Trim(')').Trim('(').Trim('<').Trim('>').Trim();
return new MailAddress(emailAddress, displayName);
}
return new MailAddress(EmailAddress);
}
Next,
Modify in function SendMail(UserInfo user, MessageType msgType, PortalSettings settings)
from orginal:
SendEmail(
settings.Email,
UserController.GetUserById(settings.PortalId, toUser).Email,
subject, body);
to:
var toUserInfo = UserController.GetUserById(settings.PortalId, toUser);SendEmail(
ConvertEmailAddress(settings.Email, settings.PortalName),
ConvertEmailAddress(toUserInfo.Email, toUserInfo.DisplayName),
subject, body);
And Modify in finaly function SendEmail(string fromAddress, string senderAddress, string toAddress, string subject, string body)
from orginal:
var emailMessage = new MailMessage(fromAddress, toAddress);
....
emailMessage.Sender = new MailAddress(senderAddress);
To:
var emailMessage = new MailMessage(GetMailAddress(fromAddress), GetMailAddress(toAddress));
....
emailMessage.Sender = GetMailAddress(senderAddress);
And result if user receiver an email from Your portal, it will be display with format " The Portal Name <adminportal@email.etc>"
Why in this editor not have code snipet??