This commit is contained in:
2022-09-06 16:04:17 +00:00
parent 715cb183a0
commit d6e7e9d6b7
5 changed files with 222 additions and 224 deletions

View File

@@ -26,21 +26,19 @@ 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_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 string MAIL_SMPT_ADDRESS = "smtp.fastmail.com";
public const int MAIL_SMPT_PORT = 465;
public const string MAIL_IMAP_ADDRESS = "mail.ayanova.com";
//public const int MAIL_IMAP_PORT = 993;
//testing
public const int MAIL_IMAP_PORT = 143;
public const string MAIL_IMAP_ADDRESS = "imap.fastmail.com";
public const int MAIL_IMAP_PORT = 993;
public const string FASTMAIL_ACCOUNT_SUPPORT = "support@onayanova.com";
public const string FASTMAIL_ACCOUNT_PASSWORD_SUPPORT = "rxwdlv4dm6kz3mhr";
public const string MAIL_ACCOUNT_SUPPORT = "support@ayanova.com";
public const string MAIL_ACCOUNT_PASSWORD_SUPPORT = "e527b6c5a00c27bb61ca694b3de0ee178cbe3f1541a772774762ed48e9caf5ce";
public const string MAIL_ACCOUNT_SALES = "sales@ayanova.com";
public const string MAIL_ACCOUNT_PASSWORD_SALES = "6edbae5eb616a975abf86bcd9f45616f5c70c4f05189af60a1caaa62b406149d";
// public const string MAIL_ACCOUNT_SALES = "sales@ayanova.com";
// public const string MAIL_ACCOUNT_PASSWORD_SALES = "6edbae5eb616a975abf86bcd9f45616f5c70c4f05189af60a1caaa62b406149d";
public enum rfMailAccount
{
@@ -92,7 +90,7 @@ namespace rockfishCore.Util
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT);
client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT);
client.Send(message);
client.Disconnect(true);
@@ -112,7 +110,7 @@ namespace rockfishCore.Util
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT);
client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT);
client.Send(message);
client.Disconnect(true);
@@ -144,7 +142,7 @@ namespace rockfishCore.Util
}
//send with optional tracking
DoSend(message, MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT, trackDeliveryStatus);
DoSend(message, FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT, trackDeliveryStatus);
// using (var client = new SmtpClient())
// {
@@ -170,42 +168,42 @@ namespace rockfishCore.Util
/// <summary>
/// Forward a message to the isspam@ayanova.com address and then erase it
/// </summary>
/// <param name="spamMessageId"></param>
/// <param name="replyFromAccount"></param>
public static void HandleSpamMessage(uint spamMessageId, rfMailAccount replyFromAccount)
{
using (var client = new ImapClient())
{
// Accept all SSL certificates
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
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 (replyFromAccount == rfMailAccount.support)
{
client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT);
}
else
{
client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
}
// /// <summary>
// /// Forward a message to the isspam@ayanova.com address and then erase it
// /// </summary>
// /// <param name="spamMessageId"></param>
// /// <param name="replyFromAccount"></param>
// public static void HandleSpamMessage(uint spamMessageId, rfMailAccount replyFromAccount)
// {
// using (var client = new ImapClient())
// {
// // Accept all SSL certificates
// client.ServerCertificateValidationCallback = (s, c, h, e) => true;
// 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 (replyFromAccount == rfMailAccount.support)
// {
// client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT);
// }
// else
// {
// client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
// }
var spamFolder = client.GetFolder("Spam");
// 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);
}
}//spaminator
// client.Disconnect(true);
// }
// }//spaminator
#endregion
@@ -213,49 +211,49 @@ namespace rockfishCore.Util
/// <summary>
/// Move to sub or unsub mail folder and mark as read
/// </summary>
/// <param name="moveMessageId"></param>
/// <param name="replyFromAccount"></param>
public static void MoveAndMarkRead(uint moveMessageId, rfMailAccount replyFromAccount, bool toSubscribed)
{
using (var client = new ImapClient())
{
// Accept all SSL certificates
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
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 (replyFromAccount == rfMailAccount.support)
{
client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT);
}
else
{
client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
}
// /// <summary>
// /// Move to sub or unsub mail folder and mark as read
// /// </summary>
// /// <param name="moveMessageId"></param>
// /// <param name="replyFromAccount"></param>
// public static void MoveAndMarkRead(uint moveMessageId, rfMailAccount replyFromAccount, bool toSubscribed)
// {
// using (var client = new ImapClient())
// {
// // Accept all SSL certificates
// client.ServerCertificateValidationCallback = (s, c, h, e) => true;
// 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 (replyFromAccount == rfMailAccount.support)
// {
// client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT);
// }
// else
// {
// client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
// }
//AyaNovaReceivedNOTSUB
//AyaNovaReceivedSubscribed
// //AyaNovaReceivedNOTSUB
// //AyaNovaReceivedSubscribed
//Flag as read
//flag the message as having been replied to
FlagMessageSeen(moveMessageId, replyFromAccount);
// //Flag as read
// //flag the message as having been replied to
// FlagMessageSeen(moveMessageId, replyFromAccount);
var newFolder = client.GetFolder(toSubscribed ? "AyaNovaReceivedSubscribed" : "AyaNovaReceivedNOTSUB");
// var newFolder = client.GetFolder(toSubscribed ? "AyaNovaReceivedSubscribed" : "AyaNovaReceivedNOTSUB");
if (newFolder != null)
{
client.Inbox.Open(FolderAccess.ReadWrite);
client.Inbox.MoveTo(new UniqueId(moveMessageId), newFolder);
}
// if (newFolder != null)
// {
// client.Inbox.Open(FolderAccess.ReadWrite);
// client.Inbox.MoveTo(new UniqueId(moveMessageId), newFolder);
// }
client.Disconnect(true);
}
}//spaminator
// client.Disconnect(true);
// }
// }//spaminator
#endregion
@@ -276,19 +274,19 @@ namespace rockfishCore.Util
MailboxAddress from = null;
string from_account = "";
string from_account_password = "";
switch (replyFromAccount)
{
case rfMailAccount.sales:
from_account = MAIL_ACCOUNT_SALES;
from_account_password = MAIL_ACCOUNT_PASSWORD_SALES;
// switch (replyFromAccount)
// {
// case rfMailAccount.sales:
// from_account = MAIL_ACCOUNT_SALES;
// from_account_password = MAIL_ACCOUNT_PASSWORD_SALES;
// from = new MailboxAddress("", from_account);
// break;
// default:
from_account = FASTMAIL_ACCOUNT_SUPPORT;
from_account_password = FASTMAIL_ACCOUNT_PASSWORD_SUPPORT;
from = new MailboxAddress("", from_account);
break;
default:
from_account = MAIL_ACCOUNT_SUPPORT;
from_account_password = MAIL_ACCOUNT_PASSWORD_SUPPORT;
from = new MailboxAddress("", from_account);
break;
}
// break;
// }
reply.From.Add(from);
// reply to the sender of the message
@@ -412,14 +410,14 @@ namespace rockfishCore.Util
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
if (fromAccount == rfMailAccount.support)
{
client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT);
}
else
{
client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
}
// if (fromAccount == rfMailAccount.support)
// {
client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT);
// }
// else
// {
// client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
// }
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly);
@@ -443,7 +441,7 @@ namespace rockfishCore.Util
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT);
client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT);
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly);
@@ -469,14 +467,14 @@ namespace rockfishCore.Util
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
if (inAccount == rfMailAccount.support)
{
client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT);
}
else
{
client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
}
// if (inAccount == rfMailAccount.support)
// {
client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT);
// }
// else
// {
// client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
// }
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadWrite);
@@ -501,14 +499,14 @@ namespace rockfishCore.Util
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
if (inAccount == rfMailAccount.support)
{
client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT);
}
else
{
client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
}
// if (inAccount == rfMailAccount.support)
// {
client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT);
// }
// else
// {
// client.Authenticate(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES);
// }
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadWrite);
@@ -571,7 +569,7 @@ namespace rockfishCore.Util
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT);
client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT);
var draftFolder = client.GetFolder("Drafts");//Our surgemail server works with this other servers in future might not
@@ -601,8 +599,8 @@ namespace rockfishCore.Util
{
List<rfMessageSummary> ret = new List<rfMessageSummary>();
ret.AddRange(getInboxSummariesFor(MAIL_ACCOUNT_SUPPORT, MAIL_ACCOUNT_PASSWORD_SUPPORT));
ret.AddRange(getInboxSummariesFor(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES));
ret.AddRange(getInboxSummariesFor(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_ACCOUNT_PASSWORD_SUPPORT));
// ret.AddRange(getInboxSummariesFor(MAIL_ACCOUNT_SALES, MAIL_ACCOUNT_PASSWORD_SALES));
return ret;
}
@@ -715,14 +713,14 @@ namespace rockfishCore.Util
client.AuthenticationMechanisms.Remove("XOAUTH2");
//TODO: make accounts reside in dictionary in future
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);
}
// if (mailAccount == "support@ayanova.com")
// {
client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_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);
@@ -807,22 +805,22 @@ namespace rockfishCore.Util
//https://github.com/jstedfast/MailKit/issues/515#issuecomment-439438242
client.CheckCertificateRevocation = false;
//client.Connect(MAIL_IMAP_ADDRESS, MAIL_IMAP_PORT, true);
if (mirrorServer)
client.Connect(MAIL_MIRROR_IMAP_ADDRESS, MAIL_IMAP_PORT);
else
// 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);
}
// if (mailAccount == "support@ayanova.com")
// {
client.Authenticate(FASTMAIL_ACCOUNT_SUPPORT, FASTMAIL_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);