📩IMAP Echo bot
IMAP
Demo Code
PerigeeApplication.ApplicationNoInit("SASL Google", (c) => {
var SASLGoogle = MailWatcher.SASL_GoogleAPIS("[email protected]", "mailbot_google_auth.json");
c.AddIMAPWatcher("EmailBot", "[email protected]", "FromMe", "smtp.gmail.com", 587, "smtp.gmail.com", 993, () => SASLGoogle, (ct, l, mail) => {
try
{
if (!mail.IsAnswered)
{
var From = mail.FromAddresses().FirstOrDefault()?.Name ?? "";
var SaidWhat = mail.GetOnlyInputTextBody();
var attachments = mail.Message.Attachments.Count();
mail.Reply(false, (b) => {
b.HtmlBody = $"Hello <b>{From}</b><br /> You said: {SaidWhat}<br />Attachments: {attachments}";
b.TextBody = $"Hello {From}\r\n You said: {SaidWhat}\r\nAttachments: {attachments}";
});
mail.AddFlags(MailKit.MessageFlags.Answered | MailKit.MessageFlags.Seen);
mail.AddLabels("bot");
}
}
catch (Exception ex)
{
l.LogError(ex, "Uncaught exception in mail processor");
try
{
mail.AddFlags(MessageFlags.Answered | MailKit.MessageFlags.Seen);
mail.AddLabels("error");
} catch (Exception) { }
}
});
});Last updated

