Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Mail Recovery System #2375

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions Intersect.Server/Notifications/Notification.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.IO;
using System.Net;
using Intersect.Logging;
using Intersect.Server.Localization;
using MailKit.Net.Smtp;
Expand All @@ -9,10 +8,8 @@

namespace Intersect.Server.Notifications
{

public partial class Notification
{

public Notification(string to, string subject = "", bool html = false)
{
ToAddress = to;
Expand All @@ -30,22 +27,29 @@ public Notification(string to, string subject = "", bool html = false)

public bool Send()
{
//Check and see if smtp is even setup
// Check if SMTP is set up
if (Options.Smtp.IsValid())
{
//Make sure we have a body
// Ensure we have a body
if (!string.IsNullOrEmpty(Body))
{
try
{
//Send the email
var fromAddress = new MailboxAddress(Options.Smtp.FromName, Options.Smtp.FromAddress);
var toAddress = new MailboxAddress(ToAddress, ToAddress);
var toAddress = new MailboxAddress("Recipient", ToAddress);

using (var client = new SmtpClient())
{
client.Connect(Options.Smtp.Host, Options.Smtp.Port, Options.Smtp.UseSsl ? SecureSocketOptions.StartTls : SecureSocketOptions.Auto);
client.Authenticate(Options.Smtp.Username, Options.Smtp.Password);
client.Timeout = 20000; // 20 seconds timeout

// Attempt to connect to the SMTP server
client.Connect(Options.Smtp.Host, Options.Smtp.Port, SecureSocketOptions.SslOnConnect);

// Authenticate if necessary
if (!string.IsNullOrEmpty(Options.Smtp.Username) && !string.IsNullOrEmpty(Options.Smtp.Password))
{
client.Authenticate(Options.Smtp.Username, Options.Smtp.Password);
}

var message = new MimeMessage();
message.To.Add(toAddress);
Expand All @@ -63,6 +67,7 @@ public bool Send()
}
message.Body = bodyBuilder.ToMessageBody();

// Send the message
client.Send(message);
client.Disconnect(true);
}
Expand Down Expand Up @@ -90,7 +95,7 @@ public bool Send()
Subject +
") to " +
ToAddress +
". Reason: SMTP not configured!"
". Reason: Body is empty!"
);
return false;
}
Expand Down Expand Up @@ -138,7 +143,5 @@ protected bool LoadFromTemplate(string templatename, string username)

return false;
}

}

}
Loading