Skip to content

Commit 55bea3e

Browse files
Version Bump: v9.0.11: Issue #399: Allow for empty strings to be passed in as text or html content in the MailHelper
1 parent 16c588b commit 55bea3e

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [9.0.11] - 2017-02-17
5+
## Update
6+
- Issue #399: Allow for empty strings to be passed in as text or html content in the MailHelper
7+
- Thanks to [@Angry-Leprechaun](https://github.com/Angry-Leprechaun) for the heads up!
8+
49
## [9.0.10] - 2017-02-16
510
## Fix
611
- Issue #395: Remove dependency for Microsoft.AspNetCore.Http.Abstractions in .NET 4

src/SendGrid/Helpers/Mail/MailHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public static SendGridMessage CreateSingleEmail(
3131
var msg = new SendGridMessage();
3232
msg.SetFrom(from);
3333
msg.SetSubject(subject);
34-
if (plainTextContent != null)
34+
if (plainTextContent != null && plainTextContent != string.Empty)
3535
{
3636
msg.AddContent(MimeType.Text, plainTextContent);
3737
}
3838

39-
if (htmlContent != null)
39+
if (htmlContent != null && htmlContent != string.Empty)
4040
{
4141
msg.AddContent(MimeType.Html, htmlContent);
4242
}

src/SendGrid/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
// The following GUID is for the ID of the typelib if this project is exposed to COM
2323
[assembly: Guid("377c20e4-2297-488f-933b-fb635c56d8fc")]
2424

25-
[assembly: AssemblyInformationalVersion("9.0.10")]
25+
[assembly: AssemblyInformationalVersion("9.0.11")]

src/SendGrid/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@
4747
}
4848
}
4949
},
50-
"version": "9.0.10"
50+
"version": "9.0.11"
5151
}

tests/SendGrid.Tests/Integration.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,21 @@ public void TestCreateSingleEmail()
330330
"Plain Text Content",
331331
null);
332332
Assert.True(msg3.Serialize() == "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject\"}],\"content\":[{\"type\":\"text/plain\",\"value\":\"Plain Text Content\"}]}");
333+
334+
var msg4 = MailHelper.CreateSingleEmail(new EmailAddress("[email protected]", "Example User"),
335+
new EmailAddress("[email protected]"),
336+
"Test Subject",
337+
"",
338+
"HTML Content");
339+
Assert.True(msg4.Serialize() == "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject\"}],\"content\":[{\"type\":\"text/html\",\"value\":\"HTML Content\"}]}");
340+
341+
var msg5 = MailHelper.CreateSingleEmail(new EmailAddress("[email protected]", "Example User"),
342+
new EmailAddress("[email protected]"),
343+
"Test Subject",
344+
"Plain Text Content",
345+
"");
346+
Assert.True(msg5.Serialize() == "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject\"}],\"content\":[{\"type\":\"text/plain\",\"value\":\"Plain Text Content\"}]}");
347+
333348
}
334349

335350
[Fact]
@@ -363,6 +378,21 @@ public void TestCreateSingleEmailToMultipleRecipients()
363378
);
364379
Assert.True(msg3.Serialize() == "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"subject\":\"Test Subject\",\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}]},{\"to\":[{\"email\":\"[email protected]\"}]},{\"to\":[{\"email\":\"[email protected]\"}]}],\"content\":[{\"type\":\"text/plain\",\"value\":\"Plain Text Content\"}]}");
365380

381+
var msg4 = MailHelper.CreateSingleEmailToMultipleRecipients(new EmailAddress("[email protected]", "Example User"),
382+
emails,
383+
"Test Subject",
384+
"",
385+
"HTML Content"
386+
);
387+
Assert.True(msg4.Serialize() == "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"subject\":\"Test Subject\",\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}]},{\"to\":[{\"email\":\"[email protected]\"}]},{\"to\":[{\"email\":\"[email protected]\"}]}],\"content\":[{\"type\":\"text/html\",\"value\":\"HTML Content\"}]}");
388+
389+
var msg5 = MailHelper.CreateSingleEmailToMultipleRecipients(new EmailAddress("[email protected]", "Example User"),
390+
emails,
391+
"Test Subject",
392+
"Plain Text Content",
393+
""
394+
);
395+
Assert.True(msg5.Serialize() == "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"subject\":\"Test Subject\",\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}]},{\"to\":[{\"email\":\"[email protected]\"}]},{\"to\":[{\"email\":\"[email protected]\"}]}],\"content\":[{\"type\":\"text/plain\",\"value\":\"Plain Text Content\"}]}");
366396
}
367397

368398
[Fact]
@@ -412,6 +442,28 @@ public void TestCreateMultipleEmailsToMultipleRecipients()
412442
substitutions
413443
);
414444
Assert.True(msg3.Serialize() == "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject1\",\"substitutions\":{\"-name-\":\"Name1\"}},{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject2\",\"substitutions\":{\"-name-\":\"Name1\"}},{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject3\",\"substitutions\":{\"-name-\":\"Name1\"}}],\"content\":[{\"type\":\"text/plain\",\"value\":\"Hello -name-\"}]}");
445+
446+
plainTextContent = "";
447+
htmlContent = "Goodbye -name-";
448+
var msg4 = MailHelper.CreateMultipleEmailsToMultipleRecipients(new EmailAddress("[email protected]", "Example User"),
449+
emails,
450+
subjects,
451+
plainTextContent,
452+
htmlContent,
453+
substitutions
454+
);
455+
Assert.True(msg4.Serialize() == "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject1\",\"substitutions\":{\"-name-\":\"Name1\"}},{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject2\",\"substitutions\":{\"-name-\":\"Name1\"}},{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject3\",\"substitutions\":{\"-name-\":\"Name1\"}}],\"content\":[{\"type\":\"text/html\",\"value\":\"Goodbye -name-\"}]}");
456+
457+
plainTextContent = "Hello -name-";
458+
htmlContent = "";
459+
var msg5 = MailHelper.CreateMultipleEmailsToMultipleRecipients(new EmailAddress("[email protected]", "Example User"),
460+
emails,
461+
subjects,
462+
plainTextContent,
463+
htmlContent,
464+
substitutions
465+
);
466+
Assert.True(msg5.Serialize() == "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject1\",\"substitutions\":{\"-name-\":\"Name1\"}},{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject2\",\"substitutions\":{\"-name-\":\"Name1\"}},{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Test Subject3\",\"substitutions\":{\"-name-\":\"Name1\"}}],\"content\":[{\"type\":\"text/plain\",\"value\":\"Hello -name-\"}]}");
415467
}
416468

417469
[Fact]

0 commit comments

Comments
 (0)