Skip to content

Commit 0232c66

Browse files
committed
final refactor and all attachment cases tested, SMTP good
1 parent 392421c commit 0232c66

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/ExceptionReporter/Mail/MailSender.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ private void SmtpClient_SendCompleted(object sender, System.ComponentModel.Async
7373
public void SendMapi(string exceptionReport)
7474
{
7575
var mapi = new SimpleMapi();
76-
var attacher = new AttachAdapter(mapi);
7776

7877
mapi.AddRecipient(_reportInfo.EmailReportAddress, null, false);
7978

80-
AttachFiles(attacher);
79+
AttachFiles(new AttachAdapter(mapi));
8180
mapi.Send(EmailSubject, exceptionReport);
8281
}
8382

@@ -93,7 +92,7 @@ private void AttachFiles(IAttach attacher)
9392
filesToAttach.Add(ScreenshotTaker.GetImageAsFile(_reportInfo.ScreenshotImage));
9493
}
9594

96-
var existingFilesToAttach = filesToAttach.Where(f => File.Exists(f)).ToList();
95+
var existingFilesToAttach = filesToAttach.Where(File.Exists).ToList();
9796

9897
foreach (var zf in existingFilesToAttach.Where(f => f.EndsWith(".zip"))) {
9998
attacher.Attach(zf); // attach external zip files separately

src/WinFormsDemoApp/DemoAppView.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,30 @@ private static void Throw_CustomMessage_Click(object sender, EventArgs e)
4242
{
4343
var file1 = Path.GetTempFileName() + "-file1.txt";
4444
var file2 = Path.GetTempFileName() + "-file2.txt";
45-
var file3 = Path.GetTempFileName() + "-file3.zip";
45+
// var file3 = Path.GetTempFileName() + "-file3.zip";
4646

4747
File.WriteAllText(file1, "test text file 1");
4848
File.WriteAllText(file2, "test text file 2");
49-
File.WriteAllText(file3, "test text file 3");
49+
// File.WriteAllText(file3, "test text file 3");
5050

5151
var exceptionReporter = new ExceptionReporter();
5252
var config = exceptionReporter.Config;
5353

5454
config.ShowAssembliesTab = false;
55-
config.FilesToAttach = new[] { file1, file2, file3 };
55+
config.FilesToAttach = new[] { file1, file2 };// , file3 };
5656
config.TakeScreenshot = true;
5757

5858
//--- Test SMTP
59-
//config.MailMethod = ExceptionReportInfo.EmailMethod.SMTP;
60-
//config.SmtpPort = 587;
61-
//config.SmtpServer= "smtp.gmail.com";
62-
//config.SmtpUsername = "<user>";
63-
//config.SmtpUseSsl = true; // NB you'll need to have "Allow less secure apps: ON" if using gmail for this
64-
//config.SmtpPassword = "<password>";
65-
//config.SmtpFromAddress = "[email protected]";
66-
//config.EmailReportAddress = "<user>";
67-
//----
68-
59+
config.MailMethod = ExceptionReportInfo.EmailMethod.SMTP;
60+
config.SmtpServer= "smtp.gmail.com";
61+
config.SmtpPort = 587;
62+
config.SmtpUsername = "<user>";
63+
config.SmtpPassword = "<password>";
64+
config.SmtpFromAddress = "[email protected]";
65+
config.EmailReportAddress = "<emailto>";
66+
config.SmtpUseSsl = true; // NB you'll need to have "Allow less secure apps: ON" if using gmail for this
67+
//----
68+
6969
exceptionReporter.Show("temp files will be attached to the email sent", exception);
7070
}
7171
}

0 commit comments

Comments
 (0)