|
|
@ -12,7 +12,10 @@ namespace Sevomin.Models.Helpers |
|
|
|
{ |
|
|
|
EmailConfirmation, |
|
|
|
PasswordReset, |
|
|
|
NewPassword |
|
|
|
NewPassword, |
|
|
|
NewApplication, |
|
|
|
NewJob, |
|
|
|
ExpiringJob |
|
|
|
} |
|
|
|
|
|
|
|
public class SevominEmailer |
|
|
@ -23,6 +26,9 @@ namespace Sevomin.Models.Helpers |
|
|
|
private string EmailConfirmationFilePath; |
|
|
|
private string NewPasswordFilePath; |
|
|
|
private string PasswordResetFilePath; |
|
|
|
private string ExpiringJobFilePath; |
|
|
|
private string NewJobFilePath; |
|
|
|
private string NewApplicationFilePath; |
|
|
|
public SevominEmailer() |
|
|
|
{ |
|
|
|
EmailFolderPath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/app_data"), "emails"); |
|
|
@ -31,12 +37,21 @@ namespace Sevomin.Models.Helpers |
|
|
|
EmailConfirmationFilePath = Path.Combine(EmailFolderPath, "email-confirmation.html"); |
|
|
|
NewPasswordFilePath = Path.Combine(EmailFolderPath, "new-password.html"); |
|
|
|
PasswordResetFilePath = Path.Combine(EmailFolderPath, "password-reset.html"); |
|
|
|
ExpiringJobFilePath = Path.Combine(EmailFolderPath, "expiring-job.html"); |
|
|
|
NewJobFilePath = Path.Combine(EmailFolderPath, "new-job.html"); |
|
|
|
NewApplicationFilePath = Path.Combine(EmailFolderPath, "new-application.html"); |
|
|
|
if(!File.Exists(EmailConfirmationFilePath)) |
|
|
|
throw new ApplicationException("Email confirmation template does not exist in the right address."); |
|
|
|
if (!File.Exists(NewPasswordFilePath)) |
|
|
|
throw new ApplicationException("New password template does not exist in the right address."); |
|
|
|
if (!File.Exists(PasswordResetFilePath)) |
|
|
|
throw new ApplicationException("Password reset template does not exist in the right address."); |
|
|
|
if (!File.Exists(ExpiringJobFilePath)) |
|
|
|
throw new ApplicationException("Expiring job template does not exist in the right address."); |
|
|
|
if (!File.Exists(NewJobFilePath)) |
|
|
|
throw new ApplicationException("New job template does not exist in the right address."); |
|
|
|
if (!File.Exists(NewApplicationFilePath)) |
|
|
|
throw new ApplicationException("New application template does not exist in the right address."); |
|
|
|
Parameters = new Dictionary<string, string>(); |
|
|
|
} |
|
|
|
public SevominEmailer(Dictionary<string, string> parameters, EmailType emailType) : this() |
|
|
@ -64,6 +79,18 @@ namespace Sevomin.Models.Helpers |
|
|
|
template = |
|
|
|
File.ReadAllText(NewPasswordFilePath, Encoding.UTF8); |
|
|
|
break; |
|
|
|
case EmailType.ExpiringJob: |
|
|
|
template = |
|
|
|
File.ReadAllText(ExpiringJobFilePath, Encoding.UTF8); |
|
|
|
break; |
|
|
|
case EmailType.NewApplication: |
|
|
|
template = |
|
|
|
File.ReadAllText(NewApplicationFilePath, Encoding.UTF8); |
|
|
|
break; |
|
|
|
case EmailType.NewJob: |
|
|
|
template = |
|
|
|
File.ReadAllText(NewJobFilePath, Encoding.UTF8); |
|
|
|
break; |
|
|
|
default: |
|
|
|
template = string.Empty; |
|
|
|
break; |
|
|
@ -75,7 +102,7 @@ namespace Sevomin.Models.Helpers |
|
|
|
msg.SubjectEncoding = Encoding.UTF8; |
|
|
|
msg.BodyEncoding = Encoding.UTF8; |
|
|
|
msg.Subject = subject; |
|
|
|
msg.IsBodyHtml = isHtml; |
|
|
|
msg.IsBodyHtml = isHtml; |
|
|
|
Func<string> getBody = () => |
|
|
|
{ |
|
|
|
foreach (var param in Parameters) |
|
|
@ -90,4 +117,4 @@ namespace Sevomin.Models.Helpers |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |