Skip to content

Commit

Permalink
Stream Safety
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyMedway authored and Ashley Medway committed Jan 18, 2016
1 parent 8996497 commit 73183a2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions MailJetClient/MailJetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public MailJetClient(string PublicKey, string PrivateKey)
public SendResponse SendMessage(MailMessage Message)
{
var request = new RestRequest("send/message", Method.POST);
request.RequestFormat = DataFormat.Json;

if (Message.From == null)
throw new InvalidOperationException("You must specify the from address. http://dev.mailjet.com/guides/send-api-guide/");
Expand Down Expand Up @@ -93,7 +92,11 @@ public SendResponse SendMessage(MailMessage Message)
{
foreach (var item in view.LinkedResources)
{
request.AddFile("inlineattachment", ((MemoryStream)item.ContentStream).ToArray(), item.ContentId, item.ContentType.MediaType);
using (var ms = new MemoryStream())
{
item.ContentStream.CopyTo(ms);
request.AddFile("inlineattachment", ms.ToArray(), item.ContentId, item.ContentType.MediaType);
}
}
}

Expand Down

0 comments on commit 73183a2

Please sign in to comment.