Uprgade from .NET SMTPClient to MailKit as the default smtpclient does not support modern protocols.
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CsvHelper" Version="30.0.1" />
|
<PackageReference Include="CsvHelper" Version="30.0.1" />
|
||||||
<PackageReference Include="LiteDB" Version="5.0.17" />
|
<PackageReference Include="LiteDB" Version="5.0.17" />
|
||||||
|
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||||
<PackageReference Include="Npgsql" Version="8.0.2" />
|
<PackageReference Include="Npgsql" Version="8.0.2" />
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1153,6 +1153,10 @@ namespace CarCareTracker.Controllers
|
|||||||
{
|
{
|
||||||
numbersArray.Add(upgradeRecords.Min(x => x.Date.Year));
|
numbersArray.Add(upgradeRecords.Min(x => x.Date.Year));
|
||||||
}
|
}
|
||||||
|
if (odometerRecords.Any())
|
||||||
|
{
|
||||||
|
numbersArray.Add(odometerRecords.Min(x => x.Date.Year));
|
||||||
|
}
|
||||||
var minYear = numbersArray.Any() ? numbersArray.Min() : DateTime.Now.AddYears(-5).Year;
|
var minYear = numbersArray.Any() ? numbersArray.Min() : DateTime.Now.AddYears(-5).Year;
|
||||||
var yearDifference = DateTime.Now.Year - minYear + 1;
|
var yearDifference = DateTime.Now.Year - minYear + 1;
|
||||||
for (int i = 0; i < yearDifference; i++)
|
for (int i = 0; i < yearDifference; i++)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using CarCareTracker.Models;
|
using CarCareTracker.Models;
|
||||||
using System.Net.Mail;
|
using MimeKit;
|
||||||
using System.Net;
|
using MailKit.Net.Smtp;
|
||||||
|
|
||||||
namespace CarCareTracker.Helper
|
namespace CarCareTracker.Helper
|
||||||
{
|
{
|
||||||
@@ -15,13 +15,16 @@ namespace CarCareTracker.Helper
|
|||||||
{
|
{
|
||||||
private readonly MailConfig mailConfig;
|
private readonly MailConfig mailConfig;
|
||||||
private readonly IFileHelper _fileHelper;
|
private readonly IFileHelper _fileHelper;
|
||||||
|
private readonly ILogger<MailHelper> _logger;
|
||||||
public MailHelper(
|
public MailHelper(
|
||||||
IConfiguration config,
|
IConfiguration config,
|
||||||
IFileHelper fileHelper
|
IFileHelper fileHelper,
|
||||||
|
ILogger<MailHelper> logger
|
||||||
) {
|
) {
|
||||||
//load mailConfig from Configuration
|
//load mailConfig from Configuration
|
||||||
mailConfig = config.GetSection("MailConfig").Get<MailConfig>();
|
mailConfig = config.GetSection("MailConfig").Get<MailConfig>();
|
||||||
_fileHelper = fileHelper;
|
_fileHelper = fileHelper;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
public OperationResponse NotifyUserForRegistration(string emailAddress, string token)
|
public OperationResponse NotifyUserForRegistration(string emailAddress, string token)
|
||||||
{
|
{
|
||||||
@@ -118,7 +121,7 @@ namespace CarCareTracker.Helper
|
|||||||
{
|
{
|
||||||
foreach (string emailAddress in emailAddresses)
|
foreach (string emailAddress in emailAddresses)
|
||||||
{
|
{
|
||||||
SendEmail(emailAddress, emailSubject, emailBody, true, true);
|
SendEmail(emailAddress, emailSubject, emailBody);
|
||||||
}
|
}
|
||||||
return new OperationResponse { Success = true, Message = "Email Sent!" };
|
return new OperationResponse { Success = true, Message = "Email Sent!" };
|
||||||
} catch (Exception ex)
|
} catch (Exception ex)
|
||||||
@@ -126,33 +129,33 @@ namespace CarCareTracker.Helper
|
|||||||
return new OperationResponse { Success = false, Message = ex.Message };
|
return new OperationResponse { Success = false, Message = ex.Message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private bool SendEmail(string emailTo, string emailSubject, string emailBody, bool isBodyHtml = false, bool useAsync = false) {
|
private bool SendEmail(string emailTo, string emailSubject, string emailBody) {
|
||||||
string to = emailTo;
|
|
||||||
string from = mailConfig.EmailFrom;
|
string from = mailConfig.EmailFrom;
|
||||||
var server = mailConfig.EmailServer;
|
var server = mailConfig.EmailServer;
|
||||||
MailMessage message = new MailMessage(from, to);
|
var message = new MimeMessage();
|
||||||
|
message.From.Add(new MailboxAddress(from, from));
|
||||||
|
message.To.Add(new MailboxAddress(emailTo, emailTo));
|
||||||
message.Subject = emailSubject;
|
message.Subject = emailSubject;
|
||||||
message.Body = emailBody;
|
|
||||||
message.IsBodyHtml = isBodyHtml;
|
var builder = new BodyBuilder();
|
||||||
SmtpClient client = new SmtpClient(server);
|
|
||||||
client.EnableSsl = mailConfig.UseSSL;
|
builder.HtmlBody = emailBody;
|
||||||
client.Port = mailConfig.Port;
|
|
||||||
client.Credentials = new NetworkCredential(mailConfig.Username, mailConfig.Password);
|
message.Body = builder.ToMessageBody();
|
||||||
try
|
|
||||||
|
using (var client = new SmtpClient())
|
||||||
{
|
{
|
||||||
if (useAsync)
|
client.Connect(server, mailConfig.Port, MailKit.Security.SecureSocketOptions.Auto);
|
||||||
{
|
client.Authenticate(mailConfig.Username, mailConfig.Password);
|
||||||
client.SendMailAsync(message, new CancellationToken());
|
try
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
client.Send(message);
|
client.Send(message);
|
||||||
|
return true;
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex.Message);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -30,14 +30,15 @@ Read this [Getting Started Guide](https://docs.lubelogger.com/Getting%20Started)
|
|||||||
[Search Existing Issues](https://github.com/hargata/lubelog/issues)
|
[Search Existing Issues](https://github.com/hargata/lubelog/issues)
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
- Bootstrap
|
- [Bootstrap](https://github.com/twbs/bootstrap)
|
||||||
- LiteDB
|
- [LiteDB](https://github.com/mbdavid/litedb)
|
||||||
- Npgsql
|
- [Npgsql](https://github.com/npgsql/npgsql)
|
||||||
- Bootstrap-DatePicker
|
- [Bootstrap-DatePicker](https://github.com/uxsolutions/bootstrap-datepicker)
|
||||||
- SweetAlert2
|
- [SweetAlert2](https://github.com/sweetalert2/sweetalert2)
|
||||||
- CsvHelper
|
- [CsvHelper](https://github.com/JoshClose/CsvHelper)
|
||||||
- Chart.js
|
- [Chart.js](https://github.com/chartjs/Chart.js)
|
||||||
- Drawdown
|
- [Drawdown](https://github.com/adamvleggett/drawdown)
|
||||||
|
- [MailKit](https://github.com/jstedfast/MailKit)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
LubeLogger utilizes a dual-licensing model, see [License](/LICENSE) for more information
|
LubeLogger utilizes a dual-licensing model, see [License](/LICENSE) for more information
|
||||||
|
|||||||
@@ -247,6 +247,7 @@
|
|||||||
<li class="list-group-item">CsvHelper</li>
|
<li class="list-group-item">CsvHelper</li>
|
||||||
<li class="list-group-item">Chart.js</li>
|
<li class="list-group-item">Chart.js</li>
|
||||||
<li class="list-group-item">Drawdown</li>
|
<li class="list-group-item">Drawdown</li>
|
||||||
|
<li class="list-group-item">MailKit</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user