Skip to content
This repository was archived by the owner on Jun 13, 2021. It is now read-only.

Commit 4616852

Browse files
authored
Merge pull request #5 from Cape-Code/releaseEmailSenderRobustnessImprovement
Release email sender robustness improvement
2 parents cf13a90 + fdbc2ad commit 4616852

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

CapeCode.Logging/CapeCode.Logging/Email/EmailSender.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void SendPublicAccouncementSystemEmail( PublicAnnouncementSystemEmail pub
5252
}
5353

5454
public void SendEncryptedEmail( EncryptedEmail encryptedEmail ) {
55-
Logger.LogTrace( "SendEncryptedEmail", "Sending {0}", encryptedEmail.ToString() );
55+
Logger.LogTrace( $"Sending {encryptedEmail.ToString()}" );
5656

5757
if ( EmailSenderConfiguration.IsDisabled ) {
5858
// used in unit-tests to prevent mass email sending...
@@ -61,7 +61,7 @@ public void SendEncryptedEmail( EncryptedEmail encryptedEmail ) {
6161

6262
IList<MailMessage> mailMessages;
6363
if ( EmailSenderConfiguration.InSimulationMode ) {
64-
Logger.LogWarning( "SendMail", "InSimulation Mode -> Changing Recipients: {0}", EmailSenderConfiguration.AdministratorEmailAddresses.ToSeparatedString( a => a ) );
64+
Logger.LogWarning( $"InSimulation Mode -> Changing Recipients: {EmailSenderConfiguration.AdministratorEmailAddresses.ToSeparatedString( a => a )}" );
6565

6666
var simulatedEmailBody = "<div style='font-family: Arial, Verdana; font-size: 10px; font-weight: bold'>" +
6767
"This mail would have been sent to:" +
@@ -82,7 +82,7 @@ public void SendEncryptedEmail( EncryptedEmail encryptedEmail ) {
8282

8383
public void SendEmail( Email email ) {
8484

85-
Logger.LogTrace( "SendMail", "Sending {0}", email.ToString() );
85+
Logger.LogTrace( $"Sending {email.ToString()}" );
8686

8787
if ( EmailSenderConfiguration.IsDisabled ) {
8888
// used in unit-tests to prevent mass email sending...
@@ -91,7 +91,7 @@ public void SendEmail( Email email ) {
9191

9292
IList<MailMessage> mailMessages;
9393
if ( EmailSenderConfiguration.InSimulationMode ) {
94-
Logger.LogWarning( "SendMail", "InSimulation Mode -> Changing To: {0} / CC: null / BCC: null", EmailSenderConfiguration.AdministratorEmailAddresses.ToSeparatedString( a => a ) );
94+
Logger.LogWarning( $"InSimulation Mode -> Changing To: {EmailSenderConfiguration.AdministratorEmailAddresses.ToSeparatedString( a => a )} / CC: null / BCC: null" );
9595

9696
var simulatedEmailBody = "<div style='font-family: Arial, Verdana; font-size: 10px; font-weight: bold'>" +
9797
"This mail would have been sent to:" +
@@ -114,6 +114,7 @@ public void SendEmail( Email email ) {
114114

115115
private void SendMailMessages( IEnumerable<MailMessage> mailMessages ) {
116116
if ( !TrySendMailMessages( mailMessages ) ) {
117+
System.Threading.Thread.Sleep( 1000 );
117118
TrySendMailMessages( mailMessages, true );
118119
}
119120
}
@@ -135,8 +136,8 @@ private bool TrySendMailMessages( IEnumerable<MailMessage> mailMessages, bool is
135136
foreach ( var mailMessage in mailMessages ) {
136137
this.SendSmtpMailMessages( client, mailMessage );
137138
}
138-
this.Logger.LogTrace( "SendMailMessages", "Successfully finished" );
139-
} catch ( SmtpException e ) {
139+
this.Logger.LogTrace( "Successfully finished" );
140+
} catch ( Exception e ) {
140141
Exception innerMostException = e;
141142
while ( innerMostException.InnerException != null ) {
142143
innerMostException = innerMostException.InnerException;
@@ -147,8 +148,6 @@ private bool TrySendMailMessages( IEnumerable<MailMessage> mailMessages, bool is
147148
} else {
148149
throw new EmailSenderException( "Email delivery failed because of an SMTP server error: " + innerMostException.Message, e );
149150
}
150-
} catch ( Exception e ) {
151-
throw new EmailSenderException( "Email delivery failed because of an unexpected error: " + e.Message, e );
152151
}
153152
return true;
154153
}

0 commit comments

Comments
 (0)