SHARE
TWEET

Untitled

a guest Aug 14th, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. log.LogInformation("########## Starting ##########");
  2. var apiKey = "Send Grid API Key";
  3. log.LogInformation(apiKey);
  4. var client = new SendGridClient(apiKey);
  5. var from = new EmailAddress("email id", "Example User");
  6. var subject = "Sending with SendGrid is Fun";
  7. var to = new EmailAddress("email id", "Example User");
  8. var plainTextContent = "and easy to do anywhere, even with C#";
  9. var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
  10. var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
  11.  
  12. string storagefilename = "Storage file name";
  13.  
  14.  
  15. WebClient client1 = new WebClient();
  16. Stream stream = client1.OpenRead(storagefilename);
  17. StreamReader reader = new StreamReader(stream);
  18. String content = reader.ReadToEnd();
  19.  
  20. byte[] byteArray = Encoding.ASCII.GetBytes(content);
  21.  
  22. log.LogInformation("####### " + byteArray);
  23. msg.Attachments = new List<SendGrid.Helpers.Mail.Attachment>
  24.             {
  25.                 new SendGrid.Helpers.Mail.Attachment
  26.                 {
  27.                     Content = Convert.ToBase64String(byteArray),
  28.                     Filename = "Transcript.pdf",
  29.                     Disposition = "attachment"
  30.                 }
  31.             };
  32.  
  33. var response = client.SendEmailAsync(msg);
  34.  
  35. log.LogInformation("####### Mail Sent ###########");
  36.  
  37. string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top