public void SendMessage(Message message, string senderName, UserProfile profile = null, IdentityUser user = null) { if (profile == null && !String.IsNullOrWhiteSpace(message.ReceivingUserId)) { profile = _userProfileService.GetProfileByUserId(message.ReceivingUserId); } if (user == null && profile != null && profile.User != null) { user = profile.User; } if (user == null && !String.IsNullOrWhiteSpace(message.ReceivingUserId)) { user = _usersService.GetUserById(message.ReceivingUserId); } var subject = string.Format("Resgrid Message from {0}", senderName); var senderEmail = String.Empty; if (message.SendingUser != null) { senderEmail = message.SendingUser.Email; } else { senderEmail = "*****@*****.**"; } if (profile != null && profile.SendMessageEmail) { _emailProvider.SendMessageMail(user.Email, subject, message.Subject, message.Body, senderEmail, senderName, message.SentOn.ToString("G") + " UTC", message.MessageId); } }