Postfix and Altermime config. Send html emails with disclaimer - html

I am currently running a Centos 7 instance. Already installed: postfix, dovecot, altermime. Sending and receiving emails works fine. However, what I am trying to do is attach a disclaimer for every mail sent.
My problem is in the disclaimer config there is a disclaimer text option, and a disclaimer html. But my email is always sent as plain text, so I receive emails with a disclaimer showing html tags.
How can i configure postfix or altermime to send html emails, or send a plain text with an image attached?
Here's my disclaimer config:
from_address=`grep -m 1 "From:" in.$$ | cut -d "<" -f 2 | cut -d ">" -f 1`
if [ `grep -wi ^${from_address}$ ${DISCLAIMER_ADDRESSES}` ]; then
/usr/bin/altermime --input=in.$$ \
--disclaimer-html=/etc/postfix/disclaimer.html \
--disclaimer=/etc/postfix/disclaimer.txt \
--force-for-bad-html \
--xheader="X-Copyrighted-Material: Please visit http://www.company.com/privacy.h$
{ echo Message content rejected; exit $EX_UNAVAILABLE; }
fi
I've tried adding the html text in disclaimer.txt, or in disclaimer.html. The email is always received as plain text showing the html tags.
Any help would be gladly appreciated.

Related

Parse XML from not well formed page using xpath

Notice:
While writing this question, I notice that there is a Github API that solves my problem without HTML parsing: https://api.github.com/repos/mozilla/geckodriver/releases/latest I decided to ask it anyway since I'm intested how to solve the described problem of parsing malformed HTML itself. So please dont downvote because there is a github API for it! We can replace github by any other page throwing validation errors.
I want to download the latest version of geckodriver. By fetching the redirection target of the latest tag, I'm on the releases page
curl $(curl -s "https://github.com/mozilla/geckodriver/releases/latest" --head | grep -i location | awk '{print $2}' | sed 's/\r//g') > /tmp/geckodriver.html
The first assets with geckodriver-vx.xxx-linux64.tar.gz is the required link. Since XML is schemantic, it should be parsed properly. Different tools like xmllint could parse it using xpaths. Since xpath is new for me, I tried a simple query on the header. But xmllint throws a lot of errors:
$ xmllint --xpath '//div[#class=Header]' /tmp/geckodriver.html
/tmp/geckodriver.html:51: parser error : Specification mandate value for attribute data-pjax-transient
<meta name="selected-link" value="repo_releases" data-pjax-transient>
^
/tmp/geckodriver.html:107: parser error : Opening and ending tag mismatch: link line 105 and head
</head>
^
/tmp/geckodriver.html:145: parser error : Entity 'nbsp' not defined
Sign up
^
/tmp/geckodriver.html:172: parser error : Entity 'rarr' not defined
es <span class="Bump-link-symbol float-right text-normal text-gray-light">→
...
There are a lot more. It seems that the github page is not properly well formed, as the specification requires it. I also tried xmlstarlet
xmlstarlet sel -t -v -m '//div[#class=Header]' /tmp/geckodriver.html
but the result is similar.
Is it not possible to extract some data using those tools when the HTML is not well formed?
curl $(curl -s "https://github.com/mozilla/geckodriver/releases/latest" --head | grep -i location | awk '{print $2}' | sed 's/\r//g') > /tmp/geckodriver.html
It may be simpler to use -L, and have curl follow the redirection:
curl -L https://github.com/mozilla/geckodriver/releases/latest
Then, xmllint accepts an --html argument, to use an HTML parser:
xmllint --html --xpath '//div[#class=Header]'
However, this doesn't match anything on that page, so perhaps you want to base your XPath on something like:
'string((//a[span[contains(.,"linux")]])[1]/#href)'
Which yields:
/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux32.tar.gz

Reading HTML in a string message while sending mail in bash script

I have my script for sending email to some user in Linux. I want to read the string content as HTML in bash, but bash is not able to read string as HTML.
Start of Script:
body ='
Dear $user,
<p> The password for your account is due to expire on in 14 days. and must be changed.<br>
<p>You can reset your password by visiting the Password Reset Portal.</p>
<p>Google </p>
<p>You can contact the XYZ Team in case of any issue. </p>'
#send email
user='ABC'
email="abc#gmail.co."
from="xyz#gmail.com"
echo $body1 | mail -s test -r $from $email
I wanted my message to user will be shown as below and read string as html
Dear ABC,
The password for your account is due to expire on in 14 days. and must be changed.
You can reset your password by visiting the Password Reset Portal.
Google
You can contact the XYZ Team in case of any issue
However bash is reading the body as a string and not as HTML as below
Dear ABC,
<p> The password for your account is due to expire on in 14 days. and must be changed.</p><br>
<p>You can reset your password by visiting the Password Reset Portal.</p>
<p>Google </p>
<p>You can contact the XYZ Team in case of any issue. </p>
Please anyone can help me on this.
I have tried the answers from the link Sending HTML mail using a shell script but i am not succeeded.
The first issue is that mail is a generic name for quite a few different programs (depending on OS and distro), and sometimes mail is a symlink to some other program (eg, mailx). Net result is that it's going to be hard to troubleshoot your issue without a good bit more detail on the program you're using called mail. This in turn can make (semi) portability of scripts a real b*tch (even between hosts in the same domain). For these reasons I tend to use sendmail when I need to do some special formatting on the body of an email.
The second issue is that most mail programs need to be instructed to interpret (html) tags. This typically includes adding (at the top of the email) the clauses MIME-VERSION: 1.0 and Content-Type: text/html.
One simple example you could start with:
body="Dear $user,
<p> The password for your account is due to expire on in 14 days. and must be changed.<br>
<p>You can reset your password by visiting the Password Reset Portal.</p>
<p>Google </p>
<p>You can contact the XYZ Team in case of any issue. </p>"
email="abc#gmail.co."
from="xyz#gmail.com"
echo "Subject: My test subject
To: ${email}
From: ${from}
MIME-Version: 1.0
Content-type: text/html
<html><body>
${body}
</body></html>" | /usr/sbin/sendmail -t
NOTE: Verify the path on your host for sendmail.
NOTE: If you don't have sendmail installed then that's a whole 'nother post since the sysadmin will need to setup a config file to tell sendmail how to process (e)mail messages (eg, what's the name of the smtp server?).
With this basic wrapper you should be able to add more html tags as needed.

How do i make the "Send email" button work in a Boostrap template?

For my website, i use a free template form startbootstrap.com, in this template there is a "Send Mail" button, i tried to get it running, but it doest, work. How can i make it work?
I have already changed the mailto#something.com to my real email and it didnt work. I am not very experienced in web developing, so it might be a very simple thing. Any help would be much appreciated
Here is the code section for the email part: \n
The only line i changed was :
action="mailto:myreal#mail.com" method="POST" enctype="text/plain">
This section tells me that i should configure my web server differently if things dont work, how would i do that
<!-- The form should work on most web servers, but if the form is not working you may need to configure your web server differently. -->
I expected this part, to just send an email to me from the provided email addres with the given content, but when i try to run it it says:
Sorry, it seems that my mail server is not responding. Please try again later!
Thanks in advance!
I don't know which template you have chosen, but with "Freelancer" there's a contact_me.php located under mail folder, where you should configure this part:
$to = "yourname#yourdomain.com"; // Add your email address inbetween the "" replacing yourname#yourdomain.com - This is where the form will send a message to.
$subject = "Website Contact Form: $name";
$body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email\n\nPhone: $phone\n\nMessage:\n$message";
$header = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$header .= "Reply-To: $email";
Since you need php and mail server for this to work, after configuration you can deploy it to a server like xampp or wampp if you'd like to test it locally or just copy it to a real webserver.

Deeplinking URLs don't show up in Branch.io Dashboard

I am using branch.io for my android app. I am trying to generate via POST method and this is the code:
{"branch_key":"key_test_lerbZ22zyjfpfFtl2auzukafywi220dN", "campaign":"new_product_annoucement", "channel":"email", "tags":["monday", "test123"],
"data":"{\"name\": \"Alex\", \"email\": \"alex#branch.io\", \"user_id\": \"12346\", \"$desktop_url\": \"https://file.town/download/odrqliwc94d440jt08wxngceo\",\"$marketing_title\": \"2\"}"}
In the dashboard, the campaign can be seen, the channel can be seen, and the generated URL goes to the desired site. But the generated URL does not show up in the Marketing tab in the dashboard to show the URL's statistics with regards to clicks, downloads and installs.
Is there any code I am missing in it?
To use the Branch HTTP API to create a link that shows up in the Marketing section of the Branch dashboard you need to add the parameter "type":2 at the root level of the request. You will also want to use a $marketing_title that is descriptive.
Here is an updated curl request using the parameters you provided:
curl -X POST -H "Content-Type: application/json" -d '{"type":2, "branch_key":"key_test_lerbZ22zyjfpfFtl2auzukafywi220dN", "campaign":"new_product_annoucement", "channel":"email", "tags":["monday", "test123"], "data":"{\"name\": \"Alex\", \"email\": \"alex#branch.io\", \"user_id\": \"12346\", \"$desktop_url\": \"https://file.town/download/odrqliwc94d440jt08wxngceo\",\"$marketing_title\": \"Super Amazing Branch Link\"}"}' https://api.branch.io/v1/url

Output Shell Script Variable to HTML

Rather new to coding, looking for a little help with having a variable output to a local html file. Both script and html are on the same machine. Script pulls signal level from a modem and I would like to have that displayed to a local html loading screen.
Signal Script:
#!/bin/bash
MODEM=/dev/ttyUSB3
MODEMCMD=AT+CSQ
{
echo -ne "$MODEMCMD"'\r\n' > "$MODEM"
if [ $? -eq 1 ]
then
echo "error";
exit;
fi
{
while read -t 1
do
if [[ $REPLY == +CSQ* ]]
then
arr1=$(echo "$REPLY" | cut -d' ' -f2)
arr2=$(echo "$arr1" | cut -d',' -f1)
echo "$arr2"
exit;
fi
done
echo "error";
} <"$MODEM"
} 2>/dev/null
Would like the output of this to display in a table on my html. Thanks!
When you host your own web server, the CGI protocol allows you to do server-side programming in any language you like; including Bash.
Here's a simple example that serves a web page that displays the current date and time, and refreshes every 10 seconds. Put the Bash script below in a file named test.cgi in the cgi-bin folder (on Linux/Apache: /usr/lib/cgi-bin) and make it executable (chmod +x test.cgi). The page's URL is: http://MyWebServer/cgi-bin/test.cgi
#!/bin/bash
cat << EOT
content-type: text/html
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta http-equiv="refresh" content="10" />
</head>
<body>
$(date)
</body>
</html>
EOT
Please note: the empty line below content-type is relevant in the CGI protocol.
Replace date by your own Bash script; make sure it outputs something that resembles valid HTML. This means you need to take some effort to add HTML tags for your markup, and HTML-encode some characters (< > &) in your content.