I didn't understand one thing. Even though I created a transactional email template on sendgrid.com and referenced it on my code, I had to had a Content object to the Mail object and the message arrived as text/plain (probably because of the Content object).
How can I use just the template created on the website?
var sg = new SendGridAPIClient(".....");
var from = new Email("[email protected]", "Name");
String subject = "The subject";
var to = new Email(txtEmail.Text, txtNome.Text);
var mail = new Mail();
mail.TemplateId = "...........";
var content = new Content();
content.Type = "text/plain";
content.Value = "Textual content";
mail.AddContent(content);
var memStream = new MemoryStream();
openFileDialog1.OpenFile().CopyTo(memStream);
String file = Convert.ToBase64String(memStream.ToArray());
var attachment = new Attachment();
attachment.Filename = "file.pdf";
attachment.Content = file;
attachment.Type = "application/pdf";
attachment.Disposition = "attachment";
attachment.ContentId = "certificado";
mail.AddAttachment(attachment);
var personalization = new Personalization();
personalization.Tos = new List<Email>();
personalization.Tos.Add(to);
personalization.AddSubstitution("%NOME%", txtNome.Text);
mail.AddPersonalization(personalization);
mail.From = from;
mail.Subject = subject;
dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
Hi juliano,Change content.Type = "text/plain" to content.Type = "text/html" Then it should work RegardsDennis Sent from my BlackBerry 10 smartphone. From: Juliano NunesSent: Thursday, 14 July 2016 10:02To: sendgrid/sendgrid-csharpReply To: sendgrid/sendgrid-csharpSubject: [sendgrid/sendgrid-csharp] How to send e-mail using template (#272)I didn't understand one thing. Even though I created a transactional email template on sendgrid.com and referenced it on my code, I had to had a Content object to the Mail object and the message arrived as text/plain (probably because of the Content object).
How can I use just the template created on the website?
var sg = new SendGridAPIClient(".....");
var from = new Email("[email protected]", "Name");
String subject = "The subject";
var to = new Email(txtEmail.Text, txtNome.Text);
var mail = new Mail();
mail.TemplateId = "...........";
var content = new Content();
content.Type = "text/plain";
content.Value = "Textual content";
mail.AddContent(content);
var memStream = new MemoryStream();
openFileDialog1.OpenFile().CopyTo(memStream);
String file = Convert.ToBase64String(memStream.ToArray());
var attachment = new Attachment();
attachment.Filename = "file.pdf";
attachment.Content = file;
attachment.Type = "application/pdf";
attachment.Disposition = "attachment";
attachment.ContentId = "certificado";
mail.AddAttachment(attachment);
var personalization = new Personalization();
personalization.Tos = new List<Email>();
personalization.Tos.Add(to);
personalization.AddSubstitution("%NOME%", txtNome.Text);
mail.AddPersonalization(personalization);
mail.From = from;
mail.Subject = subject;
dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.
Hi Juliano, Also, make sure your selected template is active and copy it's ID, and replace it here:mail.TemplateId = "..........."; Sent from my BlackBerry 10 smartphone. From: Juliano NunesSent: Thursday, 14 July 2016 10:02To: sendgrid/sendgrid-csharpReply To: sendgrid/sendgrid-csharpSubject: [sendgrid/sendgrid-csharp] How to send e-mail using template (#272)I didn't understand one thing. Even though I created a transactional email template on sendgrid.com and referenced it on my code, I had to had a Content object to the Mail object and the message arrived as text/plain (probably because of the Content object).
How can I use just the template created on the website?
var sg = new SendGridAPIClient(".....");
var from = new Email("[email protected]", "Name");
String subject = "The subject";
var to = new Email(txtEmail.Text, txtNome.Text);
var mail = new Mail();
mail.TemplateId = "...........";
var content = new Content();
content.Type = "text/plain";
content.Value = "Textual content";
mail.AddContent(content);
var memStream = new MemoryStream();
openFileDialog1.OpenFile().CopyTo(memStream);
String file = Convert.ToBase64String(memStream.ToArray());
var attachment = new Attachment();
attachment.Filename = "file.pdf";
attachment.Content = file;
attachment.Type = "application/pdf";
attachment.Disposition = "attachment";
attachment.ContentId = "certificado";
mail.AddAttachment(attachment);
var personalization = new Personalization();
personalization.Tos = new List<Email>();
personalization.Tos.Add(to);
personalization.AddSubstitution("%NOME%", txtNome.Text);
mail.AddPersonalization(personalization);
mail.From = from;
mail.Subject = subject;
dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.
Hi Dennis. What value do I have to use with content object considering I'm using a template?
Get Outlook for Android
On Wed, Jul 13, 2016 at 11:17 PM -0300, "Dennis Jimwaga" [email protected] wrote:
Hi Juliano, Also, make sure your selected template is active and copy it's ID, and replace it here:mail.TemplateId = "..........."; Sent from my BlackBerry 10 smartphone. From: Juliano NunesSent: Thursday, 14 July 2016 10:02To: sendgrid/sendgrid-csharpReply To: sendgrid/sendgrid-csharpSubject: [sendgrid/sendgrid-csharp] How to send e-mail using template (#272)I didn't understand one thing. Even though I created a transactional email template on sendgrid.com and referenced it on my code, I had to had a Content object to the Mail object and the message arrived as text/plain (probably because of the Content object).
How can I use just the template created on the website?
var sg = new SendGridAPIClient(".....");
var from = new Email("[email protected]", "Name");
String subject = "The subject";
var to = new Email(txtEmail.Text, txtNome.Text);
var mail = new Mail();
mail.TemplateId = "...........";
var content = new Content();
content.Type = "text/plain";
content.Value = "Textual content";
mail.AddContent(content);
var memStream = new MemoryStream();
openFileDialog1.OpenFile().CopyTo(memStream);
String file = Convert.ToBase64String(memStream.ToArray());
var attachment = new Attachment();
attachment.Filename = "file.pdf";
attachment.Content = file;
attachment.Type = "application/pdf";
attachment.Disposition = "attachment";
attachment.ContentId = "certificado";
mail.AddAttachment(attachment);
var personalization = new Personalization();
personalization.Tos = new List<Email>();
personalization.Tos.Add(to);
personalization.AddSubstitution("%NOME%", txtNome.Text);
mail.AddPersonalization(personalization);
mail.From = from;
mail.Subject = subject;
dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
https://github.com/sendgrid/sendgrid-csharp/issues/272#issuecomment-232538967
Hi juliano,I don't understand your question. Can u specify which content object value you want to pass? Do mean this content.Value = "Textual content";? Sent from my BlackBerry 10 smartphone. From: Juliano NunesSent: Thursday, 14 July 2016 11:46To: sendgrid/sendgrid-csharpReply To: sendgrid/sendgrid-csharpCc: Dennis Jimwaga; CommentSubject: Re: [sendgrid/sendgrid-csharp] How to send e-mail using template (#272)
Hi Dennis. What value do I have to use with content object considering I'm using a template?
Get Outlook for Android
On Wed, Jul 13, 2016 at 11:17 PM -0300, "Dennis Jimwaga" [email protected] wrote:
Hi Juliano, Also, make sure your selected template is active and copy it's ID, and replace it here:mail.TemplateId = "..........."; Sent from my BlackBerry 10 smartphone. From: Juliano NunesSent: Thursday, 14 July 2016 10:02To: sendgrid/sendgrid-csharpReply To: sendgrid/sendgrid-csharpSubject: [sendgrid/sendgrid-csharp] How to send e-mail using template (#272)I didn't understand one thing. Even though I created a transactional email template on sendgrid.com and referenced it on my code, I had to had a Content object to the Mail object and the message arrived as text/plain (probably because of the Content object).
How can I use just the template created on the website?
var sg = new SendGridAPIClient(".....");
var from = new Email("[email protected]", "Name");
String subject = "The subject";
var to = new Email(txtEmail.Text, txtNome.Text);
var mail = new Mail();
mail.TemplateId = "...........";
var content = new Content();
content.Type = "text/plain";
content.Value = "Textual content";
mail.AddContent(content);
var memStream = new MemoryStream();
openFileDialog1.OpenFile().CopyTo(memStream);
String file = Convert.ToBase64String(memStream.ToArray());
var attachment = new Attachment();
attachment.Filename = "file.pdf";
attachment.Content = file;
attachment.Type = "application/pdf";
attachment.Disposition = "attachment";
attachment.ContentId = "certificado";
mail.AddAttachment(attachment);
var personalization = new Personalization();
personalization.Tos = new List<Email>();
personalization.Tos.Add(to);
personalization.AddSubstitution("%NOME%", txtNome.Text);
mail.AddPersonalization(personalization);
mail.From = from;
mail.Subject = subject;
dynamic response = sg.client.mail.send.post(requestBody: mail.Get());
—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
https://github.com/sendgrid/sendgrid-csharp/issues/272#issuecomment-232538967
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.
Exactly. When I tried to send without the Content object, Sendgrid return an error saying that the Content type and value should have at least one character.
If I change content.Type to text/html, do I need to repeat the template HTML on content.Value?
Hi Juliano, Can you try this:1. Remove the content type objects and do the following :String mimeType = "text/html";Content content = new Content(mimeType, message);Mail mail = new Mail(from, subject, to, content);mail.TemplateId = templateId; I'll try your code when I can, but that should work Regards Dennis Sent from my BlackBerry 10 smartphone. From: Juliano NunesSent: Thursday, 14 July 2016 18:30To: sendgrid/sendgrid-csharpReply To: sendgrid/sendgrid-csharpCc: Dennis Jimwaga; CommentSubject: Re: [sendgrid/sendgrid-csharp] How to send e-mail using template (#272)Exactly. When I tried to send without the Content object, Sendgrid return an error saying that the Content type and value should have at least one character.
If I change content.Type to text/html, do I need to repeat the template HTML on content.Value?
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.
I saw that if I use new Content("text/html", " ") (with just a space on Content value parameter) it works. The problem now is that is seems to send just the HTML version (if I try to view as text on Gmail it shows the HTML code).
Aha, now I suppose that the problem could lie in your template code.when you try to preview your template in sendgrid, do u get the desired output? Sent from my BlackBerry 10 smartphone. From: Juliano NunesSent: Thursday, 14 July 2016 19:41To: sendgrid/sendgrid-csharpReply To: sendgrid/sendgrid-csharpCc: Dennis Jimwaga; CommentSubject: Re: [sendgrid/sendgrid-csharp] How to send e-mail using template (#272)I saw that if I use new Content("text/html", " ") (with just a space on Content value parameter) it works. The problem now is that is seems to send just the HTML version (if I try to view as text on Gmail it shows the HTML code).
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.
Actually I had to do two things to solve it. First, explicitly add both content types and make sure that text/plain is added to the Contents collection prior to adding text/html.
Now it works fine. Thanks for your help.
Glad to help. Cheers Sent from my BlackBerry 10 smartphone. From: Juliano NunesSent: Thursday, 14 July 2016 19:51To: sendgrid/sendgrid-csharpReply To: sendgrid/sendgrid-csharpCc: Dennis Jimwaga; CommentSubject: Re: [sendgrid/sendgrid-csharp] How to send e-mail using template (#272)Actually I had to do two things to solve it. First, explicitly add both content types and make sure that text/plain is added to the Contents collection prior to adding text/html.
Now it works fine. Thanks for your help.
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.
Within days, the requirement for including content when you have a template defined will be removed.
@Jimwaga
Thanks for the help! Please email [email protected] with your T-shirt size and mailing address so we can send you some swag!
Hi Elmer, Really appreciate it, will continue monitoring and supporting whenever I can . I've dropped the guys an email regarding the shirt. :D Best regards Dennis Sent from my BlackBerry 10 smartphone. From: Elmer ThomasSent: Thursday, 14 July 2016 23:52To: sendgrid/sendgrid-csharpReply To: sendgrid/sendgrid-csharpCc: Dennis Jimwaga; MentionSubject: Re: [sendgrid/sendgrid-csharp] How to send e-mail using template (#272)Within days, the requirement for including content when you have a template defined will be removed.
@Jimwaga
Thanks for the help! Please email [email protected] with your T-shirt size and mailing address so we can send you some swag!
—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.
The content object is no longer required when you specify a template ID.
Thank you for your patience and support!