Mailkit mit IMAP Implementierung (6.4.1) funktioniert leider nicht mit dem neuen Mailserver
This commit is contained in:
parent
8151ceaa5b
commit
a3083680e6
Binary file not shown.
@ -35,9 +35,6 @@
|
|||||||
</startup>
|
</startup>
|
||||||
<applicationSettings>
|
<applicationSettings>
|
||||||
<bsmd.ExcelReadService.Properties.Settings>
|
<bsmd.ExcelReadService.Properties.Settings>
|
||||||
<setting name="ConnectionString" serializeAs="String">
|
|
||||||
<value>Data Source=(localdb)\Projects;Initial Catalog=nsw;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False</value>
|
|
||||||
</setting>
|
|
||||||
<setting name="SleepSeconds" serializeAs="String">
|
<setting name="SleepSeconds" serializeAs="String">
|
||||||
<value>300</value>
|
<value>300</value>
|
||||||
</setting>
|
</setting>
|
||||||
@ -50,7 +47,7 @@
|
|||||||
<setting name="ValidSender" serializeAs="Xml">
|
<setting name="ValidSender" serializeAs="Xml">
|
||||||
<value>
|
<value>
|
||||||
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||||
<string>report@bsmd.de</string>
|
<string>report@bsmd.de</string>
|
||||||
<string>hsok@gmx.de</string>
|
<string>hsok@gmx.de</string>
|
||||||
<string>bald@puls200.de</string>
|
<string>bald@puls200.de</string>
|
||||||
@ -65,7 +62,7 @@
|
|||||||
<setting name="ConfirmationDE" serializeAs="Xml">
|
<setting name="ConfirmationDE" serializeAs="Xml">
|
||||||
<value>
|
<value>
|
||||||
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||||
<string>E:\svnlager\BSMD\nsw\Deutschland\BSMD-Formblatt.xlsx</string>
|
<string>E:\svnlager\BSMD\nsw\Deutschland\BSMD-Formblatt.xlsx</string>
|
||||||
</ArrayOfString>
|
</ArrayOfString>
|
||||||
</value>
|
</value>
|
||||||
@ -73,12 +70,15 @@
|
|||||||
<setting name="ConfirmationDK" serializeAs="Xml">
|
<setting name="ConfirmationDK" serializeAs="Xml">
|
||||||
<value>
|
<value>
|
||||||
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||||
<string>E:\svnlager\BSMD\nsw\Dänemark\NSW-DK-Excel-Arrival.xlsx</string>
|
<string>E:\svnlager\BSMD\nsw\Dänemark\NSW-DK-Excel-Arrival.xlsx</string>
|
||||||
<string>E:\svnlager\BSMD\nsw\Dänemark\NSW-DK-Excel-Departure.xlsx</string>
|
<string>E:\svnlager\BSMD\nsw\Dänemark\NSW-DK-Excel-Departure.xlsx</string>
|
||||||
</ArrayOfString>
|
</ArrayOfString>
|
||||||
</value>
|
</value>
|
||||||
</setting>
|
</setting>
|
||||||
|
<setting name="ConnectionString" serializeAs="String">
|
||||||
|
<value>Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=E:\DATA\DB\NSW.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False</value>
|
||||||
|
</setting>
|
||||||
</bsmd.ExcelReadService.Properties.Settings>
|
</bsmd.ExcelReadService.Properties.Settings>
|
||||||
<bsmd.email.Properties.Settings>
|
<bsmd.email.Properties.Settings>
|
||||||
<setting name="POP3User" serializeAs="String">
|
<setting name="POP3User" serializeAs="String">
|
||||||
|
|||||||
@ -71,6 +71,9 @@ namespace bsmd.ExcelReadService
|
|||||||
|
|
||||||
Dictionary<Guid, ReportingParty> reportingPartyDict = DBManager.Instance.GetReportingPartyDict();
|
Dictionary<Guid, ReportingParty> reportingPartyDict = DBManager.Instance.GetReportingPartyDict();
|
||||||
|
|
||||||
|
// BSMDPopClient.PrintCapabilities();
|
||||||
|
// BSMDPopClient.PrintSslConnectionInfo();
|
||||||
|
|
||||||
using (BSMDPopClient bsmdPopClient = new BSMDPopClient())
|
using (BSMDPopClient bsmdPopClient = new BSMDPopClient())
|
||||||
{
|
{
|
||||||
if(bsmdPopClient.IsConnected)
|
if(bsmdPopClient.IsConnected)
|
||||||
|
|||||||
@ -12,7 +12,7 @@ namespace bsmd.ExcelReadService.Properties {
|
|||||||
|
|
||||||
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
|
||||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||||
|
|
||||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
@ -23,15 +23,6 @@ namespace bsmd.ExcelReadService.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
|
||||||
[global::System.Configuration.DefaultSettingValueAttribute("replace me!")]
|
|
||||||
public string ConnectionString {
|
|
||||||
get {
|
|
||||||
return ((string)(this["ConnectionString"]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Configuration.DefaultSettingValueAttribute("300")]
|
[global::System.Configuration.DefaultSettingValueAttribute("300")]
|
||||||
@ -108,5 +99,16 @@ namespace bsmd.ExcelReadService.Properties {
|
|||||||
return ((global::System.Collections.Specialized.StringCollection)(this["ConfirmationDK"]));
|
return ((global::System.Collections.Specialized.StringCollection)(this["ConfirmationDK"]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=E:\\DATA\\DB\\NSW.MDF;Integrated " +
|
||||||
|
"Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;Appl" +
|
||||||
|
"icationIntent=ReadWrite;MultiSubnetFailover=False")]
|
||||||
|
public string ConnectionString {
|
||||||
|
get {
|
||||||
|
return ((string)(this["ConnectionString"]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,9 +2,6 @@
|
|||||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="bsmd.ExcelReadService.Properties" GeneratedClassName="Settings">
|
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="bsmd.ExcelReadService.Properties" GeneratedClassName="Settings">
|
||||||
<Profiles />
|
<Profiles />
|
||||||
<Settings>
|
<Settings>
|
||||||
<Setting Name="ConnectionString" Type="System.String" Scope="Application">
|
|
||||||
<Value Profile="(Default)">replace me!</Value>
|
|
||||||
</Setting>
|
|
||||||
<Setting Name="SleepSeconds" Type="System.Int32" Scope="Application">
|
<Setting Name="SleepSeconds" Type="System.Int32" Scope="Application">
|
||||||
<Value Profile="(Default)">300</Value>
|
<Value Profile="(Default)">300</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
@ -40,5 +37,8 @@
|
|||||||
<string>E:\svnlager\BSMD\nsw\Dänemark\NSW-DK-Excel-Departure.xlsx</string>
|
<string>E:\svnlager\BSMD\nsw\Dänemark\NSW-DK-Excel-Departure.xlsx</string>
|
||||||
</ArrayOfString></Value>
|
</ArrayOfString></Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting Name="ConnectionString" Type="System.String" Scope="Application">
|
||||||
|
<Value Profile="(Default)">Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=E:\DATA\DB\NSW.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False</Value>
|
||||||
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
||||||
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
[assembly: AssemblyCompany("schick Informatik")]
|
[assembly: AssemblyCompany("schick Informatik")]
|
||||||
[assembly: AssemblyProduct("BSMD NSW interface")]
|
[assembly: AssemblyProduct("BSMD NSW interface")]
|
||||||
[assembly: AssemblyInformationalVersion("6.4.0")]
|
[assembly: AssemblyInformationalVersion("6.4.1")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2014-2021 schick Informatik")]
|
[assembly: AssemblyCopyright("Copyright © 2014-2021 schick Informatik")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
@ -1,4 +1,4 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
[assembly: AssemblyVersion("6.4.0.*")]
|
[assembly: AssemblyVersion("6.4.1.*")]
|
||||||
|
|
||||||
|
|||||||
@ -21,8 +21,8 @@ namespace bsmd.email
|
|||||||
{
|
{
|
||||||
public class BSMDMail : IDisposable
|
public class BSMDMail : IDisposable
|
||||||
{
|
{
|
||||||
private SmtpClient client;
|
private readonly SmtpClient client;
|
||||||
private static ILog log = LogManager.GetLogger(typeof(BSMDMail));
|
private static readonly ILog log = LogManager.GetLogger(typeof(BSMDMail));
|
||||||
|
|
||||||
internal BSMDMail()
|
internal BSMDMail()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,12 +9,19 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using OpenPop.Pop3;
|
|
||||||
using OpenPop.Mime;
|
|
||||||
using log4net;
|
using log4net;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
|
|
||||||
|
using MimeKit;
|
||||||
|
using MailKit;
|
||||||
|
using MailKit.Security;
|
||||||
|
using MailKit.Net.Pop3;
|
||||||
|
using MailKit.Net.Imap;
|
||||||
|
using MailKit.Net.Smtp;
|
||||||
|
|
||||||
|
using EmailValidation;
|
||||||
|
|
||||||
namespace bsmd.email
|
namespace bsmd.email
|
||||||
{
|
{
|
||||||
public class BSMDPopClient : IDisposable
|
public class BSMDPopClient : IDisposable
|
||||||
@ -24,7 +31,7 @@ namespace bsmd.email
|
|||||||
|
|
||||||
private readonly Pop3Client pop3Client;
|
private readonly Pop3Client pop3Client;
|
||||||
private readonly ILog _log = LogManager.GetLogger(typeof(BSMDPopClient));
|
private readonly ILog _log = LogManager.GetLogger(typeof(BSMDPopClient));
|
||||||
private int currentMail = 1;
|
private int currentMail = 0;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -35,21 +42,15 @@ namespace bsmd.email
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.pop3Client = new Pop3Client();
|
this.pop3Client = new Pop3Client();
|
||||||
|
this.pop3Client.ServerCertificateValidationCallback = ValidateServerCertificate;
|
||||||
//bool useSSL = false; // abhängig vom PORT setzen!!!
|
bool useSSL = true;
|
||||||
//if (Properties.Settings.Default.POP3Port != 110)
|
this.pop3Client.Connect(Properties.Settings.Default.POP3Server, Properties.Settings.Default.POP3Port, useSSL);
|
||||||
bool useSSL = true;
|
|
||||||
|
|
||||||
this.pop3Client.Connect(Properties.Settings.Default.POP3Server, Properties.Settings.Default.POP3Port, useSSL,
|
|
||||||
60000, 60000, new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate));
|
|
||||||
// this.pop3Client.Connect(Properties.Settings.Default.POP3Server, Properties.Settings.Default.POP3Port, useSSL);
|
|
||||||
|
|
||||||
this.pop3Client.Authenticate(Properties.Settings.Default.POP3User, Properties.Settings.Default.POP3Password);
|
this.pop3Client.Authenticate(Properties.Settings.Default.POP3User, Properties.Settings.Default.POP3Password);
|
||||||
this.IsConnected = true;
|
this.IsConnected = true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_log.ErrorFormat("Error connecting to POP3 Server: {0}", ex.Message);
|
_log.ErrorFormat("Error connecting to POP3 Server {0}: {1}", Properties.Settings.Default.POP3Server, ex.Message);
|
||||||
_log.DebugFormat("User:{0} Pw:{1}", Properties.Settings.Default.POP3User, Properties.Settings.Default.POP3Password);
|
_log.DebugFormat("User:{0} Pw:{1}", Properties.Settings.Default.POP3User, Properties.Settings.Default.POP3Password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,8 +59,8 @@ namespace bsmd.email
|
|||||||
{
|
{
|
||||||
if (this.pop3Client != null)
|
if (this.pop3Client != null)
|
||||||
{
|
{
|
||||||
if (this.pop3Client.Connected)
|
if (this.pop3Client.IsConnected)
|
||||||
this.pop3Client.Disconnect();
|
this.pop3Client.Disconnect(true);
|
||||||
this.pop3Client.Dispose();
|
this.pop3Client.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,19 +97,26 @@ namespace bsmd.email
|
|||||||
if (!IsConnected) return false;
|
if (!IsConnected) return false;
|
||||||
int messageCount = this.pop3Client.GetMessageCount();
|
int messageCount = this.pop3Client.GetMessageCount();
|
||||||
|
|
||||||
if (messageCount > (this.currentMail - 1))
|
if (messageCount > this.currentMail)
|
||||||
{
|
{
|
||||||
Message mailMessage = this.pop3Client.GetMessage(this.currentMail);
|
MimeMessage mailMessage = this.pop3Client.GetMessage(this.currentMail);
|
||||||
|
if((mailMessage.Sender != null) && EmailValidator.Validate(mailMessage.Sender.Address))
|
||||||
|
sender = mailMessage.Sender.Address;
|
||||||
|
if ((sender == null) && mailMessage.From.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (MailboxAddress ma in mailMessage.From.Mailboxes)
|
||||||
|
{
|
||||||
|
if(EmailValidator.Validate(ma.Address))
|
||||||
|
{
|
||||||
|
sender = ma.Address;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mailMessage.Headers.Sender?.HasValidMailAddress == true)
|
body = mailMessage.TextBody;
|
||||||
sender = mailMessage.Headers.Sender.MailAddress.Address;
|
messageId = mailMessage.MessageId;
|
||||||
if ((sender == null) && (mailMessage.Headers.From?.HasValidMailAddress == true))
|
subject = mailMessage.Subject;
|
||||||
sender = mailMessage.Headers.From.MailAddress.Address;
|
|
||||||
|
|
||||||
MessagePart aPart = mailMessage.FindFirstPlainTextVersion();
|
|
||||||
body = aPart?.GetBodyAsText();
|
|
||||||
messageId = mailMessage.Headers.MessageId;
|
|
||||||
subject = mailMessage.Headers.Subject;
|
|
||||||
this.currentMail++; // advance message pointer
|
this.currentMail++; // advance message pointer
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -129,30 +137,61 @@ namespace bsmd.email
|
|||||||
if (!IsConnected) return false;
|
if (!IsConnected) return false;
|
||||||
|
|
||||||
int messageCount = this.pop3Client.GetMessageCount();
|
int messageCount = this.pop3Client.GetMessageCount();
|
||||||
if (messageCount > (this.currentMail - 1))
|
if (messageCount > this.currentMail)
|
||||||
{
|
{
|
||||||
Message mailMessage = this.pop3Client.GetMessage(this.currentMail);
|
MimeMessage mailMessage = this.pop3Client.GetMessage(this.currentMail);
|
||||||
|
|
||||||
if (mailMessage.Headers.Sender?.HasValidMailAddress == true)
|
if((mailMessage.Sender != null) && EmailValidator.Validate(mailMessage.Sender.Address))
|
||||||
sender = mailMessage.Headers.Sender.MailAddress.Address;
|
sender = mailMessage.Sender.Address;
|
||||||
if ((sender == null) && (mailMessage.Headers.From?.HasValidMailAddress == true))
|
if ((sender == null) && (mailMessage.From.Count > 0))
|
||||||
sender = mailMessage.Headers.From.MailAddress.Address;
|
|
||||||
|
|
||||||
messageId = mailMessage.Headers.MessageId;
|
|
||||||
subject = mailMessage.Headers.Subject;
|
|
||||||
|
|
||||||
foreach(MessagePart part in mailMessage.FindAllAttachments())
|
|
||||||
{
|
{
|
||||||
_log.InfoFormat("found attachment named {0}, ContentType {1}", part.FileName, part.ContentType);
|
foreach (MailboxAddress ma in mailMessage.From.Mailboxes)
|
||||||
if (part.FileName.EndsWith(".xls", StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
{
|
{
|
||||||
attachmentLocalFile = Path.Combine(Properties.Settings.Default.ArchiveFolder, part.FileName);
|
if (EmailValidator.Validate(ma.Address))
|
||||||
part.Save(new FileInfo(attachmentLocalFile));
|
{
|
||||||
|
sender = ma.Address;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (part.FileName.EndsWith(".xlsx", StringComparison.InvariantCultureIgnoreCase))
|
}
|
||||||
|
|
||||||
|
messageId = mailMessage.MessageId;
|
||||||
|
subject = mailMessage.Subject;
|
||||||
|
|
||||||
|
foreach (MimeEntity attachment in mailMessage.Attachments)
|
||||||
|
{
|
||||||
|
if (attachment is MessagePart rfc822)
|
||||||
{
|
{
|
||||||
attachmentLocalFile = Path.Combine(Properties.Settings.Default.ArchiveFolder, part.FileName);
|
string filename = attachment.ContentDisposition?.FileName;
|
||||||
part.Save(new FileInfo(attachmentLocalFile));
|
if(filename == null)
|
||||||
|
{
|
||||||
|
_log.InfoFormat("attachment {0} has no filename", attachment.ContentId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_log.InfoFormat("found attachment named {0}, ContentType {1}", filename, attachment.ContentType);
|
||||||
|
|
||||||
|
if (filename.EndsWith(".xls", StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
|
filename.EndsWith(".xlsx", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
attachmentLocalFile = Path.Combine(Properties.Settings.Default.ArchiveFolder, filename);
|
||||||
|
using (var stream = File.Create(attachmentLocalFile))
|
||||||
|
rfc822.Message.WriteTo(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var part = (MimePart)attachment;
|
||||||
|
var filename = part.FileName;
|
||||||
|
if (filename != null)
|
||||||
|
{
|
||||||
|
if (filename.EndsWith(".xls", StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
|
filename.EndsWith(".xlsx", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
attachmentLocalFile = Path.Combine(Properties.Settings.Default.ArchiveFolder, filename);
|
||||||
|
using (var stream = File.Create(attachmentLocalFile))
|
||||||
|
part.Content.DecodeTo(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,14 +216,18 @@ namespace bsmd.email
|
|||||||
for (int messageIndex = messageCount; messageIndex > 0; messageIndex--)
|
for (int messageIndex = messageCount; messageIndex > 0; messageIndex--)
|
||||||
{
|
{
|
||||||
// If the Message ID of the current message is the same as the parameter given, delete that message
|
// If the Message ID of the current message is the same as the parameter given, delete that message
|
||||||
if (this.pop3Client.GetMessageHeaders(messageIndex).MessageId.Equals(messageId))
|
if (this.pop3Client.GetMessage(messageIndex).MessageId.Equals(messageId))
|
||||||
{
|
{
|
||||||
// gefunden, Nachricht laden
|
// gefunden, Nachricht laden
|
||||||
Message mailMessage = this.pop3Client.GetMessage(messageIndex);
|
MimeMessage mailMessage = this.pop3Client.GetMessage(messageIndex);
|
||||||
foreach (MessagePart part in mailMessage.FindAllAttachments())
|
foreach (MimeEntity attachment in mailMessage.Attachments)
|
||||||
{
|
{
|
||||||
if (part.FileName.EndsWith(".pdf", StringComparison.InvariantCultureIgnoreCase))
|
if(attachment is MessagePart)
|
||||||
return part.FileName;
|
{
|
||||||
|
var filename = attachment.ContentDisposition?.FileName;
|
||||||
|
if ((filename != null) && filename.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
|
||||||
|
return attachment.ContentDisposition?.FileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,10 +251,10 @@ namespace bsmd.email
|
|||||||
int messageCount = this.pop3Client.GetMessageCount();
|
int messageCount = this.pop3Client.GetMessageCount();
|
||||||
|
|
||||||
// Run trough each of these messages and download the headers
|
// Run trough each of these messages and download the headers
|
||||||
for (int messageItem = messageCount; messageItem > 0; messageItem--)
|
for (int messageItem = (messageCount - 1); messageItem >= 0; messageItem--)
|
||||||
{
|
{
|
||||||
// If the Message ID of the current message is the same as the parameter given, delete that message
|
// If the Message ID of the current message is the same as the parameter given, delete that message
|
||||||
if (this.pop3Client.GetMessageHeaders(messageItem).MessageId.Equals(messageId))
|
if (this.pop3Client.GetMessage(messageItem).MessageId.Equals(messageId))
|
||||||
{
|
{
|
||||||
// Delete
|
// Delete
|
||||||
this.pop3Client.DeleteMessage(messageItem);
|
this.pop3Client.DeleteMessage(messageItem);
|
||||||
@ -225,5 +268,86 @@ namespace bsmd.email
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region MailKit helper / info / logging funcs
|
||||||
|
|
||||||
|
#region SslConnectionInformation
|
||||||
|
|
||||||
|
public static void PrintSslConnectionInfo()
|
||||||
|
{
|
||||||
|
using (var client = new SmtpClient())
|
||||||
|
{
|
||||||
|
string host = Properties.Settings.Default.SMTPServer;
|
||||||
|
client.Connect(host, 587, SecureSocketOptions.Auto);
|
||||||
|
|
||||||
|
Console.WriteLine($"Negotiated the following SSL options with {host}:");
|
||||||
|
Console.WriteLine($" Protocol Version: {client.SslProtocol}");
|
||||||
|
Console.WriteLine($" Cipher Algorithm: {client.SslCipherAlgorithm}");
|
||||||
|
Console.WriteLine($" Cipher Strength: {client.SslCipherStrength}");
|
||||||
|
Console.WriteLine($" Hash Algorithm: {client.SslHashAlgorithm}");
|
||||||
|
Console.WriteLine($" Hash Strength: {client.SslHashStrength}");
|
||||||
|
Console.WriteLine($" Key-Exchange Algorithm: {client.SslKeyExchangeAlgorithm}");
|
||||||
|
Console.WriteLine($" Key-Exchange Strength: {client.SslKeyExchangeStrength}");
|
||||||
|
|
||||||
|
// Example Log:
|
||||||
|
//
|
||||||
|
// Negotiated the following SSL options with pop.gmail.com:
|
||||||
|
// Protocol Version: Tls12
|
||||||
|
// Cipher Algorithm: Aes128
|
||||||
|
// Cipher Strength: 128
|
||||||
|
// Hash Algorithm: Sha256
|
||||||
|
// Hash Strength: 0
|
||||||
|
// Key-Exchange Algorithm: 44550
|
||||||
|
// Key-Exchange Strength: 255
|
||||||
|
|
||||||
|
client.Disconnect(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void PrintCapabilities()
|
||||||
|
{
|
||||||
|
using (var client = new Pop3Client())
|
||||||
|
{
|
||||||
|
client.Connect(Properties.Settings.Default.POP3Server, Properties.Settings.Default.POP3Port, SecureSocketOptions.SslOnConnect);
|
||||||
|
|
||||||
|
if (client.Capabilities.HasFlag(Pop3Capabilities.Sasl))
|
||||||
|
{
|
||||||
|
var mechanisms = string.Join(", ", client.AuthenticationMechanisms);
|
||||||
|
Console.WriteLine("The POP3 server supports the following SASL mechanisms: {0}", mechanisms);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.Authenticate(Properties.Settings.Default.POP3User, Properties.Settings.Default.POP3Password);
|
||||||
|
|
||||||
|
if (client.Capabilities.HasFlag(Pop3Capabilities.Apop))
|
||||||
|
Console.WriteLine("The server supports APOP authentication.");
|
||||||
|
|
||||||
|
if (client.Capabilities.HasFlag(Pop3Capabilities.Expire))
|
||||||
|
{
|
||||||
|
if (client.ExpirePolicy > 0)
|
||||||
|
Console.WriteLine("The POP3 server automatically expires messages after {0} days", client.ExpirePolicy);
|
||||||
|
else
|
||||||
|
Console.WriteLine("The POP3 server will never expire messages.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client.Capabilities.HasFlag(Pop3Capabilities.LoginDelay))
|
||||||
|
Console.WriteLine("The minimum number of seconds between login attempts is {0}.", client.LoginDelay);
|
||||||
|
|
||||||
|
if (client.Capabilities.HasFlag(Pop3Capabilities.Pipelining))
|
||||||
|
Console.WriteLine("The POP3 server can pipeline commands, so using client.GetMessages() will be faster.");
|
||||||
|
|
||||||
|
if (client.Capabilities.HasFlag(Pop3Capabilities.Top))
|
||||||
|
Console.WriteLine("The POP3 server supports the TOP command, so it's possible to download message headers.");
|
||||||
|
|
||||||
|
if (client.Capabilities.HasFlag(Pop3Capabilities.UIDL))
|
||||||
|
Console.WriteLine("The POP3 server supports the UIDL command which means we can track messages by UID.");
|
||||||
|
|
||||||
|
client.Disconnect(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,16 +40,29 @@
|
|||||||
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="BouncyCastle.Crypto, Version=1.8.10.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Portable.BouncyCastle.1.8.10\lib\net40\BouncyCastle.Crypto.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="EmailValidation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=60f3df2f38e92638, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\EmailValidation.1.0.4\lib\net45\EmailValidation.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
|
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="OpenPop, Version=2.0.6.1120, Culture=neutral, PublicKeyToken=6bdb97f144b7efc8, processorArchitecture=MSIL">
|
<Reference Include="MailKit, Version=2.13.0.0, Culture=neutral, PublicKeyToken=4e064fe7c44a8f1b, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\OpenPop.NET.2.0.6.1120\lib\net40\OpenPop.dll</HintPath>
|
<HintPath>..\packages\MailKit.2.13.0\lib\net45\MailKit.dll</HintPath>
|
||||||
<Private>True</Private>
|
</Reference>
|
||||||
|
<Reference Include="MimeKit, Version=2.13.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\MimeKit.2.13.0\lib\net45\MimeKit.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Buffers.4.5.1\lib\netstandard1.1\System.Buffers.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Security" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="EmailValidation" version="1.0.4" targetFramework="net45" />
|
||||||
<package id="log4net" version="2.0.8" targetFramework="net45" />
|
<package id="log4net" version="2.0.8" targetFramework="net45" />
|
||||||
<package id="OpenPop.NET" version="2.0.6.1120" targetFramework="net45" />
|
<package id="MailKit" version="2.13.0" targetFramework="net45" />
|
||||||
|
<package id="MimeKit" version="2.13.0" targetFramework="net45" />
|
||||||
|
<package id="Portable.BouncyCastle" version="1.8.10" targetFramework="net45" />
|
||||||
|
<package id="System.Buffers" version="4.5.1" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
||||||
Loading…
Reference in New Issue
Block a user