Cleanup and fixes

This commit is contained in:
2013-01-12 14:58:33 -05:00
parent bc019923d2
commit e50052d41e
27 changed files with 240 additions and 156 deletions
+19 -5
View File
@@ -1,5 +1,6 @@
using System.Configuration;
using System.Net.Mail;
using System.Reflection;
using MileageTraker.Web.Models;
using log4net;
@@ -10,15 +11,16 @@ namespace MileageTraker.Web.Email
/// </summary>
public class EmailNotificationService
{
//private static readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private readonly string _emaialFromAddress;
private readonly string _resetPasswordSubject;
private readonly string _resetPasswordBody;
private readonly string _initializePasswordSubject;
private readonly string _initializePasswordBody;
private readonly SmtpClient _smtpClient;
private string _initializePasswordSubject;
private string _initializePasswordBody;
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Object"/> class.
@@ -45,13 +47,25 @@ namespace MileageTraker.Web.Email
public void SendResetPassword(User user, string url)
{
var body = string.Format(_resetPasswordBody, url);
_smtpClient.Send(new MailMessage(_emaialFromAddress, user.Email, _resetPasswordSubject, body));
SendMessage(new MailMessage(_emaialFromAddress, user.Email, _resetPasswordSubject, body));
}
public void SendInitializePassword(User user, string url)
{
var body = string.Format(_initializePasswordBody, url, user.FullName);
_smtpClient.Send(new MailMessage(_emaialFromAddress, user.Email, _initializePasswordSubject, body));
SendMessage(new MailMessage(_emaialFromAddress, user.Email, _initializePasswordSubject, body));
}
private void SendMessage(MailMessage mailMessage)
{
try
{
_smtpClient.Send(mailMessage);
}
catch (SmtpException ex)
{
Logger.Error("Failed to send mail", ex);
}
}
}
}