63 lines
3.0 KiB
C#
63 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Net.Mail;
|
|
using System.Threading.Tasks;
|
|
using EnVisage.Properties;
|
|
|
|
namespace EnVisage.Code
|
|
{
|
|
public class MailManager
|
|
{
|
|
private const string INVITATION_MESSAGE_SUBJECT = "Activate your Prevu account";
|
|
private const string INVITATION_MESSAGE_BODY = "Hello, {{user_name}}. {{new_line}}{{new_line}}Please activate your Prevu account by clicking the following link: {{activation_link}}. {{new_line}}{{new_line}}Thank you!";
|
|
private const string RESTORE_PASSWORD_MESSAGE_SUBJECT = "Restore password";
|
|
private const string RESTORE_PASSWORD_MESSAGE_BODY = "Hello, {{user_name}}. {{new_line}}{{new_line}}You can restore your Prevu account by clicking the following link: {{activation_link}}. {{new_line}}{{new_line}}Thank you!";
|
|
|
|
public static void SendInvitationMessage(string email, string userName, string userId)
|
|
{
|
|
string text = INVITATION_MESSAGE_BODY;
|
|
|
|
string link;
|
|
if(HttpContext.Current.Request.Url.Port == 80 || HttpContext.Current.Request.Url.Port == 443)
|
|
link = string.Format("{2}://{1}/Account/Activate/?userId={0}", userId, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Scheme);
|
|
else
|
|
link = string.Format("{3}://{1}:{2}/Account/Activate/?userId={0}",
|
|
userId,
|
|
HttpContext.Current.Request.Url.Host,
|
|
HttpContext.Current.Request.Url.Port, HttpContext.Current.Request.Url.Scheme);
|
|
|
|
text = text.Replace("{{user_name}}", userName);
|
|
text = text.Replace("{{activation_link}}", link);
|
|
text = text.Replace("{{new_line}}", Environment.NewLine);
|
|
|
|
SendMessage(INVITATION_MESSAGE_SUBJECT, email, text);
|
|
}
|
|
public static void SendRestorePasswordMessage(string email, Guid token, string userName)
|
|
{
|
|
string text = RESTORE_PASSWORD_MESSAGE_BODY;
|
|
|
|
string link;
|
|
if (HttpContext.Current.Request.Url.Port == 80 || HttpContext.Current.Request.Url.Port == 443)
|
|
link = string.Format("{2}://{1}/Account/RestorePassword/?token={0}", token, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Scheme);
|
|
else
|
|
link = string.Format("{3}://{1}:{2}/Account/RestorePassword/?token={0}", token, HttpContext.Current.Request.Url.Host,
|
|
HttpContext.Current.Request.Url.Port, HttpContext.Current.Request.Url.Scheme);
|
|
|
|
text = text.Replace("{{user_name}}", userName);
|
|
text = text.Replace("{{activation_link}}", link);
|
|
text = text.Replace("{{new_line}}", Environment.NewLine);
|
|
|
|
SendMessage(RESTORE_PASSWORD_MESSAGE_SUBJECT, email, text);
|
|
}
|
|
|
|
private static void SendMessage(string subject, string emailTo, string text)
|
|
{
|
|
var recipient = Settings.Default.IsEmailTestMode ? "envisage.tulasoft@gmail.com" : emailTo;
|
|
var message = new MailMessage("support@prevuplan.com", recipient, subject, text);
|
|
var client = new SmtpClient();
|
|
client.Send(message);
|
|
}
|
|
}
|
|
} |