ExchangeProvider.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using InABox.Core;
  2. using InABox.Mail;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace InABox.API
  9. {
  10. public class ExchangeProvider : ISMSProvider
  11. {
  12. private ExchangeMailer Mailer;
  13. public ExchangeProvider(string host, int port, string username, string password)
  14. {
  15. Mailer = new ExchangeMailer()
  16. {
  17. MailboxHost = host,
  18. MailboxPort = port,
  19. MailboxUserName = username,
  20. MailboxPassword = password
  21. };
  22. }
  23. public SMSProviderType ProviderType => SMSProviderType.Exchange;
  24. public TwoFactorAuthenticationType TwoFactorAuthenticationType => TwoFactorAuthenticationType.Email;
  25. public bool SendMessage(string recipient, string message)
  26. {
  27. if (Mailer.Connect())
  28. {
  29. var imapMessage = Mailer.CreateMessage();
  30. imapMessage.Subject = "Message from PRS";
  31. imapMessage.Body = message;
  32. imapMessage.IsHTML = false;
  33. imapMessage.To = new List<string> { recipient };
  34. Mailer.SendMessage(imapMessage);
  35. return true;
  36. }
  37. return false;
  38. }
  39. }
  40. }