This commit is contained in:
@@ -17,6 +17,9 @@ namespace rockfishCore.Util
|
||||
public static class RfMail
|
||||
{
|
||||
|
||||
public const string MAIL_MIRROR_SMPT_ADDRESS = "mail2.ayanova.com";
|
||||
public const string MAIL_MIRROR_IMAP_ADDRESS = "mail2.ayanova.com";
|
||||
|
||||
public const string MAIL_SMPT_ADDRESS = "mail.ayanova.com";
|
||||
public const int MAIL_SMPT_PORT = 465;
|
||||
public const string MAIL_IMAP_ADDRESS = "mail.ayanova.com";
|
||||
@@ -109,7 +112,7 @@ namespace rockfishCore.Util
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void SendMessage(string MessageFrom, string MessageTo, string MessageSubject, string MessageBody,
|
||||
bool trackDeliveryStatus = false, string CustomHeader = "", string CustomHeaderValue = "")
|
||||
@@ -183,12 +186,13 @@ namespace rockfishCore.Util
|
||||
}
|
||||
|
||||
var spamFolder = client.GetFolder("Spam");
|
||||
|
||||
if (spamFolder != null){
|
||||
client.Inbox.Open(FolderAccess.ReadWrite);
|
||||
client.Inbox.MoveTo(new UniqueId(spamMessageId), spamFolder);
|
||||
|
||||
if (spamFolder != null)
|
||||
{
|
||||
client.Inbox.Open(FolderAccess.ReadWrite);
|
||||
client.Inbox.MoveTo(new UniqueId(spamMessageId), spamFolder);
|
||||
}
|
||||
|
||||
|
||||
|
||||
client.Disconnect(true);
|
||||
}
|
||||
@@ -618,6 +622,75 @@ namespace rockfishCore.Util
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="mailAccount"></param>
|
||||
/// <param name="mailFolder"></param>
|
||||
/// <param name="mirrorServer"></param>
|
||||
/// <returns></returns>
|
||||
public static IMessageSummary GetMostRecentMessageSummary(string mailAccount, string mailFolder, bool mirrorServer)
|
||||
{
|
||||
|
||||
using (var client = new ImapClient())
|
||||
{
|
||||
// Accept all SSL certificates
|
||||
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
|
||||
//client.Connect(MAIL_IMAP_ADDRESS, MAIL_IMAP_PORT, true);
|
||||
if (mirrorServer)
|
||||
client.Connect(MAIL_MIRROR_IMAP_ADDRESS, MAIL_IMAP_PORT);
|
||||
else
|
||||
client.Connect(MAIL_IMAP_ADDRESS, MAIL_IMAP_PORT);
|
||||
// Note: since we don't have an OAuth2 token, disable
|
||||
// the XOAUTH2 authentication mechanism.
|
||||
client.AuthenticationMechanisms.Remove("XOAUTH2");
|
||||
|
||||
if (mailAccount == "support@ayanova.com")
|
||||
{
|
||||
client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT);
|
||||
}
|
||||
if (mailAccount == "sales@ayanova.com")
|
||||
{
|
||||
client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
|
||||
}
|
||||
|
||||
var fldr = client.GetFolder(mailFolder);
|
||||
fldr.Open(FolderAccess.ReadOnly);
|
||||
//---------------
|
||||
int Count = fldr.Count;
|
||||
var messages = fldr.Fetch(Count - 1, Count, MessageSummaryItems.Envelope).ToList();
|
||||
|
||||
//--------------
|
||||
client.Disconnect(true);
|
||||
if (messages.Count > 0)
|
||||
return messages[0];
|
||||
else
|
||||
return null;
|
||||
|
||||
}
|
||||
}//get message
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//Validate mirroring is working
|
||||
//
|
||||
//
|
||||
public static bool MailIsMirroringProperly()
|
||||
{
|
||||
//check that the mirror and master contain the same most recent message in
|
||||
//Sent
|
||||
//AyaNovaReceivedSubscribed
|
||||
//
|
||||
|
||||
var SentMasterSummary = GetMostRecentMessageSummary("support@ayanova.com", "Sent", false);
|
||||
var AyaNovaReceivedSubscribedSummary = GetMostRecentMessageSummary("support@ayanova.com", "AyaNovaReceivedSubscribed", false);
|
||||
var SentMirrorSummary = GetMostRecentMessageSummary("support@ayanova.com", "Sent", true);
|
||||
var AyaNovaReceivedSubscribedMirrorSummary = GetMostRecentMessageSummary("support@ayanova.com", "AyaNovaReceivedSubscribed", true);
|
||||
|
||||
return SentMasterSummary.UniqueId.Id == SentMirrorSummary.UniqueId.Id && AyaNovaReceivedSubscribedSummary.UniqueId.Id == AyaNovaReceivedSubscribedMirrorSummary.UniqueId.Id;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//----------------
|
||||
|
||||
Reference in New Issue
Block a user