Skip to content

Commit c776404

Browse files
committed
fix up some SMTP mail code paths
setting to needed to be done in constructor fixed up timing of setting attachadapter etc
1 parent a4d3c0d commit c776404

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

src/ExceptionReporter/Core/ExceptionReportInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ public void SetExceptions(IEnumerable<Exception> exceptions)
5656
public bool SmtpUseSsl { get; set; }
5757

5858
/// <summary>
59-
/// Email that is displayed in the 'Contact Information'. See <see cref="EmailReportAddress"/>
59+
/// Email that is displayed in the 'Contact Information'. />
6060
/// for the email actually used to send if using SimpleMAPI or SMTP)
6161
/// </summary>
6262
public string ContactEmail { get; set; }
6363

6464
/// <summary>
65-
/// The name of the running application using <see cref="Application.ProductName"/>
65+
/// The name of the running application using />
6666
/// </summary>
6767
public string AppName { get; set; }
6868

6969
/// <summary>
70-
/// The version of the running application using <see cref="Application.ProductVersion"/>
70+
/// The version of the running application />
7171
/// </summary>
7272
public string AppVersion { get; set; }
7373

@@ -77,7 +77,7 @@ public void SetExceptions(IEnumerable<Exception> exceptions)
7777
public string RegionInfo { get; set; }
7878

7979
/// <summary>
80-
/// The name of the running application's machine using <see cref="Environment.MachineName"/>
80+
/// The name of the running application's machine/>
8181
/// </summary>
8282
public string MachineName { get; set; }
8383

src/ExceptionReporter/ExceptionReportPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private void SendSmtpMail()
139139
catch (Exception exception)
140140
{
141141
_view.SetEmailCompletedState(false);
142-
_view.ShowErrorDialog("Unable to send email using SMTP", exception);
142+
_view.ShowErrorDialog("Unable to send email using SMTP" + Environment.NewLine + exception.Message, exception);
143143
}
144144
}
145145

src/ExceptionReporter/Mail/MailSender.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,20 @@ public void SendSmtp(string exceptionReport, CompletedMethodDelegate setEmailCom
3636
};
3737

3838
var mailMessage = CreateMailMessage(exceptionReport);
39-
_attacher = new AttachAdapter(mailMessage);
4039

4140
smtpClient.SendCompleted += delegate { setEmailCompletedState.Invoke(true); };
42-
smtpClient.SendAsync(mailMessage, null);
41+
smtpClient.SendAsync(mailMessage, "Exception Report");
4342
}
4443

4544
private MailMessage CreateMailMessage(string exceptionReport)
4645
{
47-
var mailMessage = new MailMessage
46+
var mailMessage = new MailMessage(_reportInfo.SmtpFromAddress, _reportInfo.EmailReportAddress)
4847
{
4948
BodyEncoding = Encoding.UTF8,
50-
From = new MailAddress(_reportInfo.SmtpFromAddress, null),
5149
Body = exceptionReport,
5250
Subject = EmailSubject
5351
};
54-
55-
mailMessage.To.Add(new MailAddress(_reportInfo.ContactEmail));
52+
_attacher = new AttachAdapter(mailMessage);
5653

5754
if (_reportInfo.ScreenshotAvailable)
5855
mailMessage.Attachments.Add(new Attachment(ScreenshotTaker.GetImageAsFile(_reportInfo.ScreenshotImage), ScreenshotTaker.ScreenshotMimeType));

src/WinFormsDemoApp/DemoAppView.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Windows.Forms;
44
using ExceptionReporting;
5+
using ExceptionReporting.Core;
56

67
namespace WinFormsDemoApp
78
{
@@ -44,9 +45,26 @@ private static void Throw_CustomMessage_Click(object sender, EventArgs e)
4445
// has to be a registered mime type, and be non-zero bytes, I believe (for MAPI at least) else it won't attach
4546
File.WriteAllText(file1, "test text file 1");
4647
File.WriteAllText(file2, "test text file 2");
48+
4749
var exceptionReporter = new ExceptionReporter();
50+
4851
exceptionReporter.Config.ShowAssembliesTab = false;
4952
exceptionReporter.Config.FilesToAttach = new[] { file1, file2 };
53+
54+
55+
//--- smtp
56+
// exceptionReporter.Config.MailMethod = ExceptionReportInfo.EmailMethod.SMTP;
57+
// exceptionReporter.Config.SmtpPort = 465;
58+
// exceptionReporter.Config.SmtpServer= "smtp.gmail.com";
59+
// exceptionReporter.Config.SmtpUsername = "<user>@gmail.com";
60+
// exceptionReporter.Config.SmtpUseSsl = true;
61+
// exceptionReporter.Config.SmtpPassword = "<password>";
62+
// exceptionReporter.Config.SmtpFromAddress = "[email protected]";
63+
//
64+
// exceptionReporter.Config.EmailReportAddress = "<user>@gmail.com";
65+
//----
66+
67+
5068
exceptionReporter.Show("This is a custom message. As another test, 2 temp files will be attached to the email sent", exception);
5169
}
5270
}
@@ -77,7 +95,7 @@ private static void ShowMultipleExceptionReporter()
7795
exceptionReporter.Show(exception1, exception2);
7896
}
7997

80-
private static void ShowExceptionReporter(bool useConfig)
98+
private static void ShowExceptionReporter(bool useSMTP)
8199
{
82100
try
83101
{

0 commit comments

Comments
 (0)