Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Email with DisplayName each portal instantEmail with DisplayName each portal instant
Previous
 
Next
New Post
12/28/2011 12:23 AM
 

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??

https://www.onednn.com
 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Email with DisplayName each portal instantEmail with DisplayName each portal instant


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out