Files
MileageTraker/Web/Email/EmailNotification.cs
T

45 lines
1.4 KiB
C#

using System.Configuration;
using System.Net.Mail;
using MileageTraker.Web.Models;
using log4net;
namespace MileageTraker.Web.Email
{
/// <summary>
/// Email Notification
/// </summary>
public class EmailNotificationService
{
//private static readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private readonly string _resetPasswordBody;
private readonly string _resetPasswordFromAddress;
private readonly string _resetPasswordSubject;
private readonly SmtpClient _smtpClient;
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Object"/> class.
/// </summary>
/// <param name="smtpClient">The SMTP client.</param>
public EmailNotificationService()
{
_smtpClient = new SmtpClient();
_resetPasswordBody = ConfigurationManager.AppSettings["ResetPasswordBody"];
_resetPasswordFromAddress = ConfigurationManager.AppSettings["ResetPasswordFromAddress"];
_resetPasswordSubject = ConfigurationManager.AppSettings["ResetPasswordSubject"];
}
/// <summary>
/// Sends the reset password email.
/// </summary>
/// <param name="user">To this user.</param>
/// <param name="url">Reset url</param>
public void NotifyResetPassword(User user, string url)
{
var body = string.Format(_resetPasswordBody, url);
_smtpClient.Send(new MailMessage(_resetPasswordFromAddress, user.Email, _resetPasswordSubject, body));
}
}
}