Page 1 of 1

e-mail headers - Content-type: text/html

Posted: Fri Jun 01, 2012 1:20 am
by snowkiterdude
I am customizing the usage report scripts in order to organize the data better and implement lowering a users speeds after their data cap is hit. To do this I need to be able to send e-mails with the header Content-type: text/html.

I have not been able to find any information on how to make this work.


The reliant code:
------------------------------------------------------------------------------------
:set text "$combinedtext <tr><td>$sitename:</td><td>$percentage% of $gigs GB</td><td>$megsdowncurrent MB</td><td>$megsupcurrent MB</td></tr>"
:set combinedtext "$text"

/tool e-mail send server="<my email server>" from="monitor@mycompany.com" to="$email" subject="Usage report on $date at $time" body="Site Usage Report
$text
Regards, monitor@mycompany.com"
:log info "Email sent to $email"
-----------------------------------------------------------------------------------
Here are the options I have under the Mikrotik send function. (RouterOS 5.5)
/tool e-mail send
body cc file from password port server subject tls to user
/tool e-mail edit
address from password port user value-name
/tool e-mail export
file hide-sensitive
/tool e-mail get
address from password port user value-name
/tool e-mail set
address from password port user
-----------------------------------------------------------------------------------
I usually do the same thing in php by:
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
and then use php's mail function and it works great.
-----------------------------------------------------------------------------------
We have to be able to add headers right?
A little help would be much appreciated.
Thanks in advance

Re: e-mail headers - Content-type: text/html

Posted: Fri Jun 01, 2012 9:49 am
by janisk
custom headers are not currently planned as a feature for e-mail tool.

Re: e-mail headers - Content-type: text/html

Posted: Fri Jun 01, 2012 6:32 pm
by snowkiterdude
That's a bummer. Their are allot of e-mails these days that are no longer in plan text.

Does anyone know of any other ways that you can format e-mails without html/xml. My plan was to though all the data into an array that I could loop though to organize the data. Then through that data into a html table that could then be e-mailed and exported into excel for structured data and coloured graphs.

Or maybe I could have my web server add the header for me? Maybe a bash script that would add the text/html header on all e-mails coming from a certain source e-mail address.

Re: e-mail headers - Content-type: text/html

Posted: Fri Jun 01, 2012 7:18 pm
by boen_robot
If you really need to add custom headers, you could either:
1. Make an HTTP request to a PHP file using "/tool fetch". You can pass all needed variables into the URL. Once in PHP, you can add any additional headers you want, and send the mail from PHP.
2. Instead of sending the email to your email's real SMTP server, send it to another SMTP server, which you'd configure to forward the message to the real SMTP server, after adding additional headers to it. If you have control over the "real" SMTP server, you could directly configure it instead (just make sure to apply the rule only if the SMTP connection is from the router; you probably don't want to add those same headers to all emails).

Re: e-mail headers - Content-type: text/html

Posted: Fri Jun 01, 2012 7:48 pm
by snowkiterdude
If you really need to add custom headers, you could either:
1. Make an HTTP request to a PHP file using "/tool fetch". You can pass all needed variables into the URL. Once in PHP, you can add any additional headers you want, and send the mail from PHP.
2. Instead of sending the email to your email's real SMTP server, send it to another SMTP server, which you'd configure to forward the message to the real SMTP server, after adding additional headers to it. If you have control over the "real" SMTP server, you could directly configure it instead (just make sure to apply the rule only if the SMTP connection is from the router; you probably don't want to add those same headers to all emails).

Awesome thanks for the reply. I should be able to do everything I need in PHP :-).

Re: e-mail headers - Content-type: text/html

Posted: Mon Jun 04, 2012 4:02 pm
by janisk
or, just use monitoring software that gathers data, sends notifications and draws beautiful graphs. Why reinvent the wheel when working solutions are already available.

Re: e-mail headers - Content-type: text/html

Posted: Mon Jun 04, 2012 4:18 pm
by boen_robot
or, just use monitoring software that gathers data, sends notifications and draws beautiful graphs. Why reinvent the wheel when working solutions are already available.
Any "of the shelf" working solution you have in mind (I know at least 4 people that would be interested, myself included)?

Re: e-mail headers - Content-type: text/html

Posted: Thu Jan 23, 2020 9:48 am
by AndreyRa
You can inject custom headers in the "subject" parameter:
/tool e-mail send to="test@test.test" subject="Subject text\r\nContent-type: text/plain;charset=windows-1251" body="Body text";

Re: e-mail headers - Content-type: text/html

Posted: Fri Jan 24, 2020 12:48 am
by Sob
Nice hack. :) But also kind of bug, I would be worried that it may get fixed.