Send an HTML email with an attachment in unix either using mail,mailx or sendmail - email

I am trying to send an HTML email along with few attachments, but i when m not using
Content-Type: text/html
in header then i am able to send the attachment , but HTML part of the email is displayed as below :-
<html>
<body>
<p>This is the body content</p>
</body>
</html>
but when m using the
Content-Type: text/html in header am able to see the HTML part of the email as below :-
This is the body content
But in this case m not able to send the attachment.
Below is the 2 sets of code am using
For set 1 :-
FILES="$(ls /dir_with_the_list_of_files_to_be_sent | awk '{print $0}' | tr '\n' ' ')"
(
echo "To: abc#abc.com"
echo "Subject:Extract List ";
echo "Content-Type: text/html"
echo
echo "<html>"
echo "<body>"
echo "<font face='Courier New' size='1'>"
echo "<h1>Hi All,</h1>"
echo "<h1>Below are the path </h1>"
echo "<br>"
echo "<font size="4"><p>Thanks & Regards,<br />
<br />
echo "`for f in $FILES ; do uuencode "$f" "$f" ; done `"
ABC</p></font>"
echo "</font>"
echo "</body>"
echo "</html>"
) | /usr/sbin/sendmail -t
For set 2 :-
FILES="$(ls /dir_with_the_list_of_files_to_be_sent | awk '{print $0}' | tr '\n' ' ')"
(
echo "To: abc#abc.com"
echo "Subject:Extract List ";
echo
echo "<html>"
echo "<body>"
echo "<font face='Courier New' size='1'>"
echo "<h1>Hi All,</h1>"
echo "<h1>Below are the path </h1>"
echo "<br>"
echo "<font size="4"><p>Thanks & Regards,<br />
<br />
echo "`for f in $FILES ; do uuencode "$f" "$f" ; done `"
ABC</p></font>"
echo "</font>"
echo "</body>"
echo "</html>"
) | /usr/sbin/sendmail -t
Could someone please suggest how can i send both the HTML part of email and attachment from unix.
Thanks in advance.

Related

I have a some scritps is working but not work in crontab

I have a some scripts and, when ı was run manually the scripts were run. But
When working in crontab, the format is incorrect.
This is for a new Linux server
awk 'BEGIN{
FS="-"
print "<HTML>""<table border="1" border="3" cellpadding="4" cellspacing="4" bgcolor=lightblue><TH>Firma</TH><TH>Charged Party No</TH><TH>Pcom Status</TH>"
}
{
printf "<TR>"
for(i=1;i<=NF;i++)
printf "<TD>%s</TD>",$i
print "</TR>"
}
END{
print "</TABLE></BODY></HTML>"
}
' /app/ovocontrol/cp_not_found2.txt > file.html
sed -i "s/failure/<font color="red">failure<\/font>/g;s/success/<font color="green">success<\/font>/g" file.html
(
echo "To: **********"
echo "Subject: Son 10 Dakikaya ait Toplu SMS CUDB Hata Detayi"
echo "Content-Type: text/html"
echo
cat file.html
echo
) | /usr/sbin/sendmail -t
I have a some scripts and, when ı was run manually the scripts were run. But
When working in crontab, the format is incorrect.
You don't have a shebang, nor do you have a complete crontab, so I'm guessing at what you're actually doing. I suspect you are trying to call those multiple commands directly from your crontab, which is a terrible idea. Instead, put your multiple calls into a single script and invoke it from cron. eg, do something like:
$ cat > /path/to/script << 'EOF'
#!/bin/sh
: ${f:=/app/ovocontrol/cp_not_found2.txt}
{
echo "To: **********"
echo "Subject: Son 10 Dakikaya ait Toplu SMS CUDB Hata Detayi"
echo "Content-Type: text/html"
echo
printf '<HTML><table border="1" border="3" cellpadding="4" cellspacing="4"'
printf ' bgcolor=lightblue><TH>Firma</TH><TH>Charged Party No</TH><TH>Pcom Status</TH>\n'
awk -F - ' {
printf "<TR>"
for(i=1;i<=NF;i++) printf "<TD>%s</TD>",$i
print "</TR>"
}
' "$f"
printf '</TABLE></BODY></HTML>\n'
} \
| sed -e 's#failure#<font color="red">failure</font>#g' \
-e 's#success#<font color="green">success</font>#g'
| /usr/sbin/sendmail -t
EOF
$ chmod +x /path/to/script
$ printf 'i\n0 * * * * /path/to/script\n.\nw\nq\n' | EDITOR=ed crontab -e
Note that the last command above is not really a great idea, just an attempt to codify the directive to add /path/to/script to your crontab.
I solved problem other way , "awk '!seen[$0]++'" command incorrect my format. the code was actually a short portion of the code. I think crontab has a special settings.

How to right align several lines of text in PHP - newbie

I'm trying to right align a date and 6 lines of text on a letterhead using PHP, but either break the PHP code or it isn't right aligning all the text lines.
This is the existing PHP code I've adjusted to this point which right aligns the date and the first two lines, but the rest of the text lines are still on the left.
The end result I want to achieve is to align the date and the 6 lines of text after the date on the right side of the page.
<?php
echo "<br />";
echo "<br />";
echo "<div align='right'>";
echo date("d/m/Y") . "</div><br />";
echo "<br />";
echo "<br />";
$user_info = wp_get_current_user(1);
echo "<div align='right'>";
echo $user_info->first_name . " " . $user_info->last_name . "\n";
echo "Job Title</div>" . "\n";
echo 'Email: ' . $user_info->user_email. "\n";
echo 'Mobile: ' . $user_info->mobile_number. "\n";
echo 'Web Address: ' . $user_info->webaddress1. "\n";
echo 'Facebook Page: ' . $user_info->facebook. "\n";
echo "<br />";
echo "<br />";
echo "<hr />";
echo "Dear " . $_POST["c_name"] . "," . "\n";
I'm very new at this so thanks so much for any help and suggestions.
change your code at line 9
from echo "<div align='right'>";
to echo "<div style='text-align:right'>";

sed - Separate quotes and arguments

So, I'm trying to get a script I'm working on to run another script in different directories with different arguments as defined in a text file.
Here's part of my code:
for bline in $(cat "$file"); do
lindir=$()
linarg=$()
echo "dir: ${lindir}"
echo "arg: ${linarg}"
done
Let's say I have a line in file that says this:
"./puppies" -c=1 -u=0 -b=1
How can I get an output of ./puppies for lindir and an output of -c=1 -u=0 -b=1 for linarg?
lindir="$( cut -d ' ' -f 1 <<<"$bline" )"
linarg="$( cut -d ' ' -f 2- <<<"$bline" )"
That is
while read -r bline; do
lindir="$( cut -d ' ' -f 1 <<<"$bline" )"
linarg="$( cut -d ' ' -f 2- <<<"$bline" )"
printf "dir: %s\n" "$lindir"
printf "arg: %s\n" "$linarg"
done <"$file"
If you're in a shell that doesn't understand "here-strings":
lindir="$( printf "%s" "$bline" | cut -d ' ' -f 1 )"
linarg="$( printf "%s" "$bline" | cut -d ' ' -f 2- )"

Fetching data into textbox

I am trying to finish my school project.
This is what my site looks like:
I am fetching daha via the "Getir" button using AJAX. This is working very well but I want to make the second row editable.
foreach ($rows as $row) {
echo "<tr>";
echo "<td>".$row['uyeid']."</td>";
echo "<td>".$row['ad']."</td>";
echo "<td>".$row['soyad']."</td>";
echo "<td>".$row['eposta']."</td>";
echo "<td>".$row['uyestatusu']."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>$duzenlenemez</td>";
echo "<td>".$row['ad']."</td>";
echo "<td>".$row['soyad']."</td>";
echo "<td>".$row['eposta']."</td>";
echo "<td>".$row['uyestatusu']."</td>";
echo "</tr>";
}
}
I am ready to supply extra code if anyone needs it to figure out more.
For anyone interested and found this subject one google I am writing this:
As I said I wanted to make second row editable so I needed to wrote data to inputs. Like this:
foreach ($rows as $row) {
echo "<tr>";
echo "<td>".$row['uyeid']."</td>";
echo "<td>".$row['ad']."</td>";
echo "<td>".$row['soyad']."</td>";
echo "<td>".$row['eposta']."</td>";
echo "<td>".$row['uyestatusu']."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>$duzenlenemez</td>";
echo "<td><input type='text' value='".$row['ad']."'/></td>";
echo "<td><input type='text' value='".$row['soyad']."'/></td>";
echo "<td><input type='text' value='".$row['eposta']."'/></td>";
echo "<td><input type='text' value='".$row['uyestatusu']."'/></td>";
echo "</tr>";
}
}
Output picture: http://puu.sh/8uSDl.png

How to send simple text file as attachment using HP-UX shell script?

I need to send an email with a text file as attachment using shell script in HP-UX; I don't have mutt installed.
I am using following command but it sends the file content in body of email, I want it as an attachment.
mailx -s "Report" name#example.com < file.txt
I wrote this ksh function a few years ago
# usage: email_attachment to cc subject body attachment_filename
email_attachment() {
to="$1"
cc="$2"
subject="$3"
body="$4"
filename="${5:-''}"
boundary="_====_blah_====_$(date +%Y%m%d%H%M%S)_====_"
{
print -- "To: $to"
print -- "Cc: $cc"
print -- "Subject: $subject"
print -- "Content-Type: multipart/mixed; boundary=\"$boundary\""
print -- "Mime-Version: 1.0"
print -- ""
print -- "This is a multi-part message in MIME format."
print -- ""
print -- "--$boundary"
print -- "Content-Type: text/plain; charset=ISO-8859-1"
print -- ""
print -- "$body"
print -- ""
if [[ -n "$filename" && -f "$filename" && -r "$filename" ]]; then
print -- "--$boundary"
print -- "Content-Transfer-Encoding: base64"
print -- "Content-Type: application/octet-stream; name=$filename"
print -- "Content-Disposition: attachment; filename=$filename"
print -- ""
print -- "$(perl -MMIME::Base64 -e 'undef $/; open $fh, shift; print MIME::Base64::encode(<$fh>); close $fh; ' $filename)"
print -- ""
fi
print -- "--${boundary}--"
} | /usr/lib/sendmail -oi -t
}
uuencode is your friend.
Here is a tested example:
(uuencode .vimrc vimrc.txt; uuencode .zshrc zshrc.txt; echo Here are your attachments) | mailx -s 'Mail with attachments' email_address
I was having the same problem where the output of uuencode was being sent as part of the message body rather than as an attached file (at least when using Outlook 2010 to view the sent mail). I found the answer in this thread http://www.unix.com/hp-ux/41306-sending-attachments-through-mailx.html
Adding -m causes mailx to not add MIME header lines when sending email. The OP's command would be altered to look like:
mailx -m -s "Report" name#example.com < file.txt
I also encountered the same problem few months ago.
The command I needed was ux2dos
( cat message_content_file; ux2dos file.txt | uuencode file.txt file.txt ) | mailx -m -s "subject" -r mail#sender mail#recipient
I hope it can help !
Regards