Работает отправка и получение почты
This commit is contained in:
parent
0b2f2fa6aa
commit
75604db1a8
@ -19,7 +19,10 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
||||
|
||||
public bool Create(MessageInfoBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (!CheckModelIsValid(model))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_messageInfoStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
@ -41,7 +44,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
||||
return list;
|
||||
}
|
||||
|
||||
private void CheckModel(MessageInfoBindingModel model, bool withParams = true)
|
||||
private bool CheckModelIsValid(MessageInfoBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -49,7 +52,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
_logger.LogInformation("MessageInfo. MessageId: {MessageId}", model.MessageId);
|
||||
var element = _messageInfoStorage.GetElement(new MessageInfoSearchModel
|
||||
@ -58,8 +61,10 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
||||
});
|
||||
if (element != null)
|
||||
{
|
||||
throw new InvalidOperationException("Пиьсмо с таким идентификатором уже есть");
|
||||
_logger.LogDebug("Пиьсмо с таким идентификатором уже есть");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Net;
|
||||
using System.Text;
|
||||
using MailKit.Net.Pop3;
|
||||
using MailKit.Security;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SecuritySystemBusinessLogic.MailWorker
|
||||
{
|
||||
@ -38,6 +39,8 @@ namespace SecuritySystemBusinessLogic.MailWorker
|
||||
protected override async Task<List<MessageInfoBindingModel>> ReceiveMailAsync()
|
||||
{
|
||||
var list = new List<MessageInfoBindingModel>();
|
||||
string regexpPattern = "(\\<(/?[^>]+)>)";
|
||||
Regex regexp = new Regex(regexpPattern);
|
||||
using var client = new Pop3Client();
|
||||
await Task.Run(() =>
|
||||
{
|
||||
@ -56,7 +59,7 @@ namespace SecuritySystemBusinessLogic.MailWorker
|
||||
MessageId = message.MessageId,
|
||||
SenderName = mail.Address,
|
||||
Subject = message.Subject,
|
||||
Body = message.TextBody
|
||||
Body = regexp.Replace(message.HtmlBody, "")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,10 @@
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="SmtpClientHost" value="smtp.beget.com" />
|
||||
<add key="SmtpClientPort" value="465" />
|
||||
<add key="SmtpClientPort" value="2525" />
|
||||
<add key="PopHost" value="pop3.beget.com" />
|
||||
<add key="PopPort" value="995" />
|
||||
<add key="MailLogin" value="egovpidor@nspotapov.ru" />
|
||||
<add key="MailPassword" value="FGMVb$po9qFN" />
|
||||
<add key="MailLogin" value="securitysystemshop@nspotapov.ru" />
|
||||
<add key="MailPassword" value="2iD8*KBY" />
|
||||
</appSettings>
|
||||
</configuration>
|
@ -29,28 +29,40 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
buttonRefresh = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Fill;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.Location = new Point(0, 42);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersVisible = false;
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(800, 450);
|
||||
dataGridView.Size = new Size(800, 408);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Location = new Point(12, 7);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(94, 29);
|
||||
buttonRefresh.TabIndex = 1;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += buttonRefresh_Click;
|
||||
//
|
||||
// FormMails
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonRefresh);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormMails";
|
||||
Text = "Почта";
|
||||
@ -62,5 +74,6 @@
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonRefresh;
|
||||
}
|
||||
}
|
@ -38,5 +38,10 @@ namespace SecuritySystemView.Mail
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ namespace SecuritySystemView
|
||||
PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
|
||||
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
|
||||
});
|
||||
var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000);
|
||||
var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 5000);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user