Skip to content

Commit 49fbe55

Browse files
authored
Merge pull request #294 from exceptionless/feature/email
Added support for mailkit
2 parents 16d9711 + 9576acf commit 49fbe55

File tree

20 files changed

+284
-242
lines changed

20 files changed

+284
-242
lines changed

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ assembly_info:
2828
assembly_informational_version: "{version} $(GIT_HASH)"
2929

3030
before_build:
31-
- nuget sources add -Name ExceptionlessNightly -Source https://www.myget.org/F/exceptionless/api/v3/index.json
3231
- nuget restore -verbosity quiet
3332
- ps: .\build\Start-ElasticSearch.ps1 -NodeCount 1 -StartKibana $false
3433

build/Start-ElasticSearch.ps1

Lines changed: 98 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Param(
2-
[string]$Version = "5.2.2",
2+
[string]$Version = "5.3.0",
33
[int]$NodeCount = 1,
44
[bool]$StartKibana = $true,
55
[int]$StartPort = 9200,
@@ -8,98 +8,127 @@
88
)
99

1010
If ($env:JAVA_HOME -eq $null -Or -Not(Test-Path -Path $env:JAVA_HOME)) {
11-
Write-Error "Please ensure the latest version of java is installed and the JAVA_HOME environmental variable has been set."
12-
Return
11+
Write-Error "Please ensure the latest version of java is installed and the JAVA_HOME environmental variable has been set."
12+
$host.SetShouldExit(1)
13+
Return
1314
}
1415

1516
Push-Location $PSScriptRoot
1617

1718
If (-Not (Test-Path -Path "elasticsearch-$Version") -And -Not (Test-Path -Path "elasticsearch-$Version.zip")) {
18-
Write-Output "Downloading Elasticsearch $Version..."
19-
Invoke-WebRequest "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$Version.zip" -OutFile "elasticsearch-$Version.zip"
19+
Write-Output "Downloading Elasticsearch $Version..."
20+
Invoke-WebRequest "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$Version.zip" -OutFile "elasticsearch-$Version.zip"
2021
} Else {
21-
Write-Output "Using already downloaded Kibana $Version..."
22+
Write-Output "Using already downloaded Elasticsearch $Version..."
2223
}
2324

2425
If ((Test-Path -Path "elasticsearch-$Version.zip") -And !(Test-Path -Path "elasticsearch-$Version")) {
25-
Write-Output "Extracting Elasticsearch $Version..."
26-
Add-Type -assembly "system.io.compression.filesystem"
27-
[io.compression.zipfile]::ExtractToDirectory("$PSScriptRoot\elasticsearch-$Version.zip", $PSScriptRoot)
28-
Remove-Item elasticsearch-$Version.zip
26+
Write-Output "Extracting Elasticsearch $Version..."
27+
Add-Type -assembly "system.io.compression.filesystem"
28+
[io.compression.zipfile]::ExtractToDirectory("$PSScriptRoot\elasticsearch-$Version.zip", $PSScriptRoot)
29+
Remove-Item elasticsearch-$Version.zip
2930
} Else {
30-
Write-Output "Using already downloaded and extracted Elasticsearch $Version..."
31+
Write-Output "Using already downloaded and extracted Elasticsearch $Version..."
3132
}
3233

3334
For ($i = 1; $i -le $NodeCount; $i++) {
34-
$nodePort = $StartPort + $i - 1
35-
Write-Output "Starting Elasticsearch $Version node $i port $nodePort"
36-
If (-Not (Test-Path -Path ".\elasticsearch-$Version-node$i")) {
37-
Copy-Item .\elasticsearch-$Version .\elasticsearch-$Version-node$i -Recurse
38-
Copy-Item .\elasticsearch.yml .\elasticsearch-$Version-node$i\config -Force
39-
Add-Content .\elasticsearch-$Version-node$i\config\elasticsearch.yml "`nhttp.port: $nodePort"
35+
$nodePort = $StartPort + $i - 1
36+
Write-Output "Starting Elasticsearch $Version node $i port $nodePort"
37+
If (-Not (Test-Path -Path ".\elasticsearch-$Version-node$i")) {
38+
Copy-Item .\elasticsearch-$Version .\elasticsearch-$Version-node$i -Recurse
39+
Copy-Item .\elasticsearch.yml .\elasticsearch-$Version-node$i\config -Force
40+
Add-Content .\elasticsearch-$Version-node$i\config\elasticsearch.yml "`nhttp.port: $nodePort"
41+
42+
Invoke-Expression ".\elasticsearch-$Version-node$i\bin\elasticsearch-plugin.bat install mapper-size"
43+
if ($LastExitCode -ne 0) {
44+
$host.SetShouldExit($LastExitCode)
45+
Return
4046
}
47+
}
4148

42-
If ($ResetData -And (Test-Path -Path "$(Get-Location)\elasticsearch-$Version-node$i\data")) {
43-
Write-Output "Resetting node $i data..."
44-
Remove-Item "$(Get-Location)\elasticsearch-$Version-node$i\data" -Recurse -ErrorAction Ignore
45-
}
49+
If ($ResetData -And (Test-Path -Path "$(Get-Location)\elasticsearch-$Version-node$i\data")) {
50+
Write-Output "Resetting node $i data..."
51+
Remove-Item "$(Get-Location)\elasticsearch-$Version-node$i\data" -Recurse -ErrorAction Ignore
52+
}
4653

47-
Start-Process "$(Get-Location)\elasticsearch-$Version-node$i\bin\elasticsearch.bat"
54+
Start-Process "$(Get-Location)\elasticsearch-$Version-node$i\bin\elasticsearch.bat"
4855

49-
$attempts = 0
50-
Do {
51-
If ($attempts -gt 0) {
52-
Start-Sleep -s 2
53-
}
54-
55-
Write-Host "Waiting for Elasticsearch $Version node $i to respond..."
56-
$res = $null
56+
$attempts = 0
57+
$success = $false
58+
Do {
59+
If ($attempts -gt 0) {
60+
Start-Sleep -s 2
61+
}
5762

58-
Try {
59-
$res = Invoke-WebRequest http://localhost:$nodePort -UseBasicParsing
60-
} Catch {}
61-
$attempts = $attempts + 1
62-
} Until ($res -ne $null -And $res.StatusCode -eq 200 -And $attempts -lt 25)
63+
Write-Host "Waiting for Elasticsearch $Version node $i to respond ($attempts)..."
64+
$res = $null
65+
66+
Try {
67+
$res = Invoke-WebRequest http://localhost:$nodePort -UseBasicParsing
68+
If ($res -ne $null -And $res.StatusCode -eq 200) {
69+
$success = $true
70+
Break
71+
}
72+
} Catch {}
73+
$attempts = $attempts + 1
74+
} Until ($attempts -gt 15)
75+
76+
If ($success -eq $false) {
77+
Write-Error "Failed to start Elasticsearch $Version node $i."
78+
$host.SetShouldExit($LastExitCode)
79+
Return
80+
}
6381
}
6482

6583
If ($StartKibana -eq $true) {
66-
If (-Not (Test-Path -Path "kibana-$Version") -And -Not (Test-Path -Path "kibana-$Version.zip")) {
67-
Write-Output "Downloading Kibana $Version..."
68-
Invoke-WebRequest "https://artifacts.elastic.co/downloads/kibana/kibana-$Version-windows-x86.zip" -OutFile "kibana-$Version.zip"
69-
} Else {
70-
Write-Output "Using already downloaded Kibana $Version..."
71-
}
84+
If (-Not (Test-Path -Path "kibana-$Version") -And -Not (Test-Path -Path "kibana-$Version.zip")) {
85+
Write-Output "Downloading Kibana $Version..."
86+
Invoke-WebRequest "https://artifacts.elastic.co/downloads/kibana/kibana-$Version-windows-x86.zip" -OutFile "kibana-$Version.zip"
87+
} Else {
88+
Write-Output "Using already downloaded Kibana $Version..."
89+
}
7290

73-
If ((Test-Path -Path "kibana-$Version.zip") -And -Not (Test-Path -Path "kibana-$Version")) {
74-
Write-Output "Extracting Kibana $Version..."
75-
Add-Type -assembly "system.io.compression.filesystem"
76-
[io.compression.zipfile]::ExtractToDirectory("$PSScriptRoot\kibana-$Version.zip", $PSScriptRoot)
77-
Rename-Item .\kibana-$Version-windows-x86\ kibana-$Version
78-
Remove-Item kibana-$Version.zip
79-
} Else {
80-
Write-Output "Using already downloaded and extracted Kibana $Version..."
91+
If ((Test-Path -Path "kibana-$Version.zip") -And -Not (Test-Path -Path "kibana-$Version")) {
92+
Write-Output "Extracting Kibana $Version..."
93+
Add-Type -assembly "system.io.compression.filesystem"
94+
[io.compression.zipfile]::ExtractToDirectory("$PSScriptRoot\kibana-$Version.zip", $PSScriptRoot)
95+
Rename-Item .\kibana-$Version-windows-x86\ kibana-$Version
96+
Remove-Item kibana-$Version.zip
97+
} Else {
98+
Write-Output "Using already downloaded and extracted Kibana $Version..."
99+
}
100+
101+
Write-Output "Starting Kibana $Version"
102+
Start-Process "$(Get-Location)\kibana-$Version\bin\kibana.bat"
103+
$attempts = 0
104+
$success = $false
105+
Do {
106+
If ($attempts -gt 0) {
107+
Start-Sleep -s 2
81108
}
82109

83-
Write-Output "Starting Kibana $Version"
84-
Start-Process "$(Get-Location)\kibana-$Version\bin\kibana.bat"
85-
$attempts = 0
86-
Do {
87-
If ($attempts -gt 0) {
88-
Start-Sleep -s 2
89-
}
90-
91-
Write-Host "Waiting for Kibana $Version to respond..."
92-
$res = $null
93-
94-
Try {
95-
$res = Invoke-WebRequest http://localhost:5601 -UseBasicParsing
96-
} Catch {}
97-
$attempts = $attempts + 1
98-
} Until ($res -ne $null -And $res.StatusCode -eq 200 -And $attempts -lt 25)
99-
100-
If ($OpenKibana) {
101-
Start-Process "http://localhost:5601/app/kibana#/dev_tools/console"
102-
}
110+
Write-Host "Waiting for Kibana $Version to respond ($attempts)..."
111+
$res = $null
112+
113+
Try {
114+
$res = Invoke-WebRequest http://localhost:5601 -UseBasicParsing
115+
If ($res -ne $null -And $res.StatusCode -eq 200) {
116+
$success = $true
117+
Break
118+
}
119+
} Catch {}
120+
$attempts = $attempts + 1
121+
} Until ($attempts -gt 15)
122+
123+
If ($success -eq $false) {
124+
Write-Error "Failed to start Kibana $Version."
125+
$host.SetShouldExit($LastExitCode)
126+
Return
127+
}
128+
129+
If ($OpenKibana) {
130+
Start-Process "http://localhost:5601/app/kibana#/dev_tools/console"
131+
}
103132
}
104133

105134
Pop-Location

src/Exceptionless.Api/Web.config

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616
Production: Use this mode when deployed to production.
1717
-->
1818
<add key="WebsiteMode" value="Dev" />
19-
<!-- Email addresses that match this comma delimited list of domains and email addresses will be allowed to be sent out in Dev and QA mode -->
20-
<add key="AllowedOutboundAddresses" value="exceptionless.io" />
21-
<!-- All emails that do not match the AllowedOutboundAddresses will be sent to this address in Dev and QA mode -->
22-
<add key="TestEmailAddress" value="noreply@exceptionless.io" />
19+
2320
<!-- Controls whether users can signup. -->
2421
<add key="EnableAccountCreation" value="true" />
2522
<!-- Controls whether daily summary emails are sent -->
2623
<add key="EnableDailySummary" value="false" />
24+
25+
<!-- Email Client Settings (Uncomment the section below to configure email settings) -->
26+
<!--
27+
<add key="SmtpHost" value="localhost" />
28+
<add key="SmtpPort" value="25" />
29+
<add key="SmtpEnableSSL" value="false" />
30+
<add key="SmtpUser" value="" />
31+
<add key="SmtpPassword" value="" />
32+
-->
33+
2734
<!-- Folder used to store event post data -->
2835
<add key="StorageFolder" value="|DataDirectory|\storage" />
2936
<!-- Runs the jobs in the current website process -->

src/Exceptionless.Core/Bootstrapper.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,7 @@ public static void RegisterServices(Container container, ILoggerFactory loggerFa
128128

129129
container.RegisterSingleton<IEmailGenerator>(() => new RazorEmailGenerator(@"Mail\Templates"));
130130
container.RegisterSingleton<IMailer, Mailer>();
131-
if (Settings.Current.WebsiteMode != WebsiteMode.Dev) {
132-
container.RegisterSingleton<IMailSender, SmtpMailSender>();
133-
} else {
134-
container.RegisterSingleton<IMailSender>(() => new InMemoryMailSender());
135-
logger.Warn("Emails will NOT be sent in Dev mode.");
136-
}
131+
container.RegisterSingleton<IMailSender>(() => new InMemoryMailSender());
137132

138133
container.RegisterSingleton<ILockProvider, CacheLockProvider>();
139134
container.Register<StripeEventHandler>();

src/Exceptionless.Core/Exceptionless.Core.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@
325325
<Compile Include="Extensions\RequestInfoExtensions.cs" />
326326
<Compile Include="Mail\IMailSender.cs" />
327327
<Compile Include="Mail\InMemoryMailSender.cs" />
328-
<Compile Include="Mail\SmtpMailSender.cs" />
329328
<Compile Include="Plugins\EventProcessor\Default\40_RequestInfoPlugin.cs" />
330329
<Compile Include="Repositories\Exceptions\DocumentNotFoundException.cs" />
331330
<Compile Include="Extensions\MailerExtensions.cs" />
Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
3-
using System.Net.Mail;
4-
using MailMessage = Exceptionless.Core.Queues.Models.MailMessage;
3+
using Exceptionless.Core.Queues.Models;
54

65
namespace Exceptionless.Core.Extensions {
76
public static class MailerExtensions {
@@ -28,24 +27,5 @@ public static MailMessage ToMailMessage(this System.Net.Mail.MailMessage message
2827

2928
return notification;
3029
}
31-
32-
public static System.Net.Mail.MailMessage ToMailMessage(this MailMessage notification) {
33-
var message = new System.Net.Mail.MailMessage { Subject = notification.Subject };
34-
if (!String.IsNullOrEmpty(notification.To))
35-
message.To.Add(notification.To);
36-
37-
if (!String.IsNullOrEmpty(notification.From))
38-
message.From = new MailAddress(notification.From);
39-
else
40-
message.From = new MailAddress(Settings.Current.SmtpFrom);
41-
42-
if (!String.IsNullOrEmpty(notification.TextBody))
43-
message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(notification.TextBody, null, "text/plain"));
44-
45-
if (!String.IsNullOrEmpty(notification.HtmlBody))
46-
message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(notification.HtmlBody, null, "text/html"));
47-
48-
return message;
49-
}
5030
}
51-
}
31+
}

src/Exceptionless.Core/Mail/InMemoryMailSender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class InMemoryMailSender : IMailSender {
1414
public InMemoryMailSender(int messagesToStore = 25) {
1515
_messagesToStore = messagesToStore;
1616
}
17-
17+
1818
public long TotalSent => _totalSent;
1919
public List<MailMessage> SentMessages => _recentMessages.ToList();
2020
public MailMessage LastMessage => SentMessages.LastOrDefault();

0 commit comments

Comments
 (0)