123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System.Collections.Generic;
- using System.Linq;
- using Comal.Classes;
- using InABox.Core;
- using InABox.Mail;
- namespace Comal.Stores
- {
- internal class EmailStore : BaseStore<Email>
- {
- protected override void BeforeSave(Email entity)
- {
- base.BeforeSave(entity);
- var user = FindSubStore<User>().Load(new Filter<User>(x => x.UserID).IsEqualTo(UserID)).FirstOrDefault();
- if (user != null)
- {
- var mailer = new ExchangeMailer
- {
- MailboxHost = user.EmailHost, MailboxDomain = user.EmailDomain, MailboxUserName = user.EmailUserID,
- MailboxPassword = user.EmailPassword
- };
- if (mailer.Connect())
- {
- var msg = mailer.CreateMessage();
- msg.To = entity.To;
- msg.CC = entity.CC;
- msg.BCC = entity.BCC;
- msg.Subject = entity.Subject;
- msg.Body = entity.Message;
- var bOK = mailer.SendMessage(msg);
- //if (!bOK)
- // entity.History.Add(new EntityHistory() { User = UserID, Timestamp = DateTime.Now, Note = "Unable to Send Email" });
- //else
- // entity.History.Add(new EntityHistory() { User = UserID, Timestamp = DateTime.Now, Note = "Email Sent Successfully" });
- }
- //entity.History.Add(new EntityHistory() { User = UserID, Timestamp = DateTime.Now, Note = "Unable to Connect to Exchange Mail Server" });
- }
- }
- protected override void OnSave(Email entity, ref string auditnote)
- {
- // Actually, we don't want save these - (1) there's simply too many of them, (2) we're not using them (3) if we're really keen, we can trawl the logs
- //base.OnSave(entity);
- }
- protected override void OnSave(IEnumerable<Email> entities, ref string auditnote)
- {
- //base.OnSave(entities);
- }
- }
- }
|