How to Add Line Breaks to Mailgun Template - go

I am using mailgun Templates with Go to send emails. However when the text in my template fields contain \n no newline is added. My basic code looks like the following:
message := m.mg.NewMessage(sender, subject, body, recipient)
message.SetTemplate("my-template")
_ = message.AddTemplateVariable("myText", event.Text)
// ... Code for sending
I saw this answer about sending mail with newlines, however when I implement it like the following:
_ = message.AddTemplateVariable("myText", strings.ReplaceAll(event.Text, "\\n", "<br />"))
The email contains <br /> text in the body but no newlines.
I also tried adding the following field in the css of my template: white-space: pre-wrap; but still there was no break. Thanks for any help with adding a newline to a Mailgun Template with Golang.

Try to use triple-stash in your template instead of double-stash
{{var1}} -> {{{var1}}}

Related

how to transfer body.getAsync plain text with \n

I'm getting outlook email content with
Office.context.mailbox.item.body.getAsync("text", async function callback(result) {})
and the result it returned is in plain text format with no line breaks info, I want to know if there is any way to get it with \n ?
You can get the HTML string which represents the message body instead.

How to define sender's name in golang net/smtp.sendmail?

My question is short, I have a golang application from which I am trying to send an email using net/smtp.sendmail:
This is the command which I am going to use
smtp.SendMail(server, auth, **from**, to, msg)
No usually people pass the sender's email address to from. Is there anyway I can pass a sender's name as well?
So the recipient will get an email from:
Foo Bar <foo#bar.com>
instead of an email from
<foo#bar.com>
I checked the official documentation and dozens of examples online but could not find anything.
Thank you.
You could add it to the msg for example, extending the example from the official docs you could use:
msg := []byte("From: the name <sender#example.org>\r\n" +
"To: recipient#example.net\r\n" +
"Subject: discount Gophers!\r\n" +
"\r\n" +
"This is the email body.\r\n")
Notice the: From: the name <sender#example.org>
The msg parameter should be an RFC 822-style email with headers first, a blank line, and then the message body. The lines of msg should be CRLF terminated. The msg headers should usually include fields such as "From", "To", "Subject", and "Cc".

Adding a new line to the string

hi am working with wso2esb4.9.0,
I have a service which generates email in that i have property as mailbody which am using to pass as body of the email.
<property name="mailbody"
expression="fn:concat('You have received a new Ticket',':','TicketID-',get-property('Ticketid'),', ','TicketDetails-',get-property('Details'))"
scope="default"
type="STRING"/>
when am passing this property in my service am getting a mail and mail body looks like as shown below.
You have received a new Ticket: TicketID-3021668982752443, TicketDetails-Test ticket details
I want to add a new line in the value so that the mail body can look like below instead of a single line.
You have received a new Ticket:
TicketID-3021668982752443,
TicketDetails-Test ticket details
Is there any Xpath function or way to add new line to my string value.
I have tried to include \n and 
 in fn-concat of mailbody property but it is not working.
As the XPath expression is inside of an XML document doing expression="fn:concat('You have received a new Ticket',':
','TicketID-',get-property('Ticketid'),', ','TicketDetails-',get-property('Details'))" should suffice.
If you really use XPath 2.0 then you can also use expression="fn:concat('You have received a new Ticket',':', codepoints-to-string(10),'TicketID-',get-property('Ticketid'),', ','TicketDetails-',get-property('Details'))".

Best way to find nested opening and closing tags

I am making a basic discussion board using ROR. When a user posts a response to a message, the input textarea is prepopulated with the message in quotes using a tag: [QUOTE]. As such the format is:
[QUOTE]quoted message goes here[/QUOTE]
Currently, I have a simple solution that replaces [QUOTE] and [/QUOTE] with HTML using message.sub('[QUOTE]', 'html goes here') as long as [QUOTE] or [/QUOTE] still exist. When I go to respond to a quoted message, I convert the HTML back into the [QUOTE] tag to ensure that the prepopulated input textarea doesn't have HTML in it. As such, a quote of a quote, will look like:
[QUOTE][QUOTE]quoted message here[/QUOTE][/QUOTE]
Here is the problem. If I run my current method again, I will get duplicated HTML fields like:
<div class='test'><div class='test'>quoted message goes here</div></div>
Instead, I want to be able to have a solution that looks like:
<div class='test1'><div class='test2'>quoted message goes here</div></div>
And so on...
Any suggestions on the best way to loop this?
If you want to do depth tracking you'll have to use the block method for gsub:
text = "[QUOTE][QUOTE]quoted message here[/QUOTE][/QUOTE]"
quote_level = 0
new_text = text.gsub(/\[\/?QUOTE\]/) do |m|
case (m)
when '[QUOTE]'
quote_level += 1
"<div class='test#{quote_level}'>"
when '[/QUOTE]'
quote_level -= 1
"</div>"
end
end
puts new_text.inspect
# => "<div class='test1'><div class='test2'>quoted message here</div></div>"
You could make this more robust when handling invalid nesting pairs, but for well-formatted tags this should work.
Here's an idea:
Take this regex
(\[QUOTE\])(.*?)(\[\/QUOTE\])
And apply it to your string. It'll match opening tag, closing tag and content. Then take the content and apply regex again. If there are any matches, that'll be your second level of nesting. Repeat while have matches.
Demo here: http://rubular.com/r/MkGsnUj3vL

is there a way to get codeigniter to create a plain text page where \n char works properly?

I am trying to use vanilla forum with proxyconnect and it requires i give it a plain text file of my user's authentication cookie values in the form below. However, when i send it the only way i can get it to work is with the tags and i needs to have the \n tag.
document should be:
UniqueID=5
Name=Kyle
Email=email#email.com
I can get it to display like that with br tags but when i use \n tags they show up like this:
UniqueID=5\nName=Kyle\nEmail=email#email.com
here is the method in the controller
function get_user_info(){
if(!empty($this->user)){
printf('UniqueID=' . $this->user['userID'] . '\n');
printf('Name=' . $this->user['userFirst'] . '\n');
printf('Email=' . $this->user['userEmail'] . '\n');
}
}
Try to use use "\n" with double quotes instead. Special characters will not be expanded when they occur in single quoted strings.
Example
printf('Name=' . $this->user['userFirst'] . "\n");
Along with what rkj has suggested above, you need to output the page as plain text. To do this, add this to the beginning of your controller's function:
$this->output->set_header("Content-Type: text/plain");

Resources