The IMAP bot will scan an email box and respond with the text you sent it, as well as info about attachments.
To run the demo, you would need to authenticate it properly with your email server.
This demo is using SASL-OAUTH for Google GMail. If you want to supply direct username/password authentication you can do that as well.
Copy PerigeeApplication .ApplicationNoInit( "SASL Google" , (c) => {
var SASLGoogle = MailWatcher .SASL_GoogleAPIS( "fakeemailaddress@gmail.com" , "mailbot_google_auth.json" );
c .AddIMAPWatcher( "EmailBot" , "fakeemailaddress@gmail.com" , "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 ) { }
}
});
});