mail format change when received - linux

I have file.out logfile which contain plain text and formated as
1abcdefghijklmnopqrstuvwxyz
2abcdefghijklmnopqrstuvwxyz
3abcdefghijklmnopqrstuvwxyz
<--------------------
4abcdefghijklmnopqrstuvwxyz
5abcdefghijklmnopqrstuvwxyz
6abcdefghijklmnopqrstuvwxyz
My problem is when I received it in my mail box the format is changed
OUTPUT in MAILBOX
1abcdefghijklmnopqrstuvwxyz 2abcdefghijklmnopqrstuvwxyz 3abcdefghijklmnopqrstuvwxyz
<---------------
4abcdefghijklmnopqrstuvwxyz
5abcdefghijklmnopqrstuvwxyz
6abcdefghijklmnopqrstuvwxyz
the first 1,2,3 is not supposed to be in a single line. while the 4,5,6 stays formated as is.
the file was originally sent by perl script using Mail:Sendmail module, but I also tried sending through mail command to test also.
cat file.out | mail -s reportfile email#email.com got the same result.
I've also check the file and there is no extra spaces or characters.

MS Outlook 2007 issue. resolve it with this: go to Tools > Preferences > Email > Email-Options >Message handling > "Remove extra line breaks in plain text messages".

Related

Sendmail bash script read text file and add hyperlink

Below I have partial of my script. I can send email using this, my only problem is when I read text file (body.txt) it ignores new lines, because of that my body email send one big line.
if I remove
Mime-version:1.0
Content-type:text/html"
Than I it does understand new line on text file. However this time by hyperlinks because plain text, when I want to be html.
links=<a href='deleteserid=test#gmail.com'>Unsubscribe</a>
xmail="/usr/sbin/sendmail"
# Fetches subject.txt generated from input.php page.
xsub=$(cat /data3/sss/subject.txt)
# Show from in email.
xfrom="xxx.net"
# Fetches body.txt generated from input.php page.
xmsg=$(cat /data3/ssss/body.txt)
text="$xmsg <br><br> $links"
echo $text
### Compose emails one at a time, per loop.
"$xmail" "$line" << EOF
subject:$xsub
from:$xfrom
Mime-version:1.0
Content-type:text/html
$text
EOF
Instead of:
...
Content-type:text/html
$text
EOF
Replace it with:
...
Content-type:text/html
$(cat /data3/ssss/body.txt)
$xmsg <br><br> $links
EOF
According to
[https://stackoverflow.com/questions/3902455/mail-multipart-alternative-vs-multipart-mixed]
Set the Content-Type to multipart/alternative when sending HTML email messages.

Use Japanese characters in subject and attach file with mailx in RedHat Linux

I am trying to use the mailx command for sending email with attachment (zipped) and am facing two issues, below is the command I use:
(echo "$BODY"; UUENCODE $ZIP_FILE $ZIP_FILE) \
| mailx -s $SUBJECT_1 -r " " $SENDER $RECIPIENT
My email subject contains space and Japanese characters.
The variable $SUBJECT_1 has the following statement
Subject: [Budget] Subtype Error and some JAPANESE CHARECTERS
I get bet following error:
contains invalid character '\203'
Moreover for testing purpose I changed the statement of SUBJECT_1 to Test Message
SUBJECT_1="Test Message"
It worked, but I receive only Test instead of Test Message and in the mail I could see two more email ids in the To like Message#domain.com and -r#domain.com
I have not implemented the mail body yet, once subject issue fixed will implement the same in body because Body will also have Japanese characters.
Please help me with this error, how to resolve and what am i doing wrong
There's a list of things you need help with here, more than I want to to handle exhaustively on a sunny Saturday afternoon. But some hints.
Quote your variables.
"$SUBJECT_1" is a single string, whereas $SUBJECT_1 is a list of space-separated words. The second word is your email recipient, and subsequent options are also recipients.
Subject.
The basic idea is that you need to include encoding data in the subject, because email headers are only supposed to include 7-bit ASCII.
Here is a hint at how you put special characters in your Subject line.
Here is another hint.
Here is the RFC that describes in lurid detail what you need to do. Asking your favourite search engine for information about "utf8 email subject" and "rfc1522" is probably a good idea.
Email client.
Finally, rather than learning how to use MIME, consider using mutt instead of mailx to send your mail. Mutt has a -a option to add attachments, making it WAY easier than constructing your own headers and body, which I'm not even sure you'd be able to do with mailx in the first place.

mail can't send messages: Process exited with a non-zero status

I wrote a bash script that sends out a mail, but after 50 e-mails it starts to say "mail can't send messages: Process exited with a non-zero status". Can anyone help solve my problem. The code I used is below if you want to take a look at it.
#!/bin/bash
#Declare variables area.
emailBody=email_body.txt; #you have to use without “ symbol for some reason
emailList=email_list_delimiter.txt;
#send mail command. using a read file loop.
while IFS= read -r emailTo; do
cat $emailBody |
mail -s "Hi, I'm looking for a position in IT Field." $emailTo |
echo “Success”;
done < <(grep . $emailList)
You are probably hitting a server-side limit on the number of messages you can send in a fixed time, or equivalently the number of connections allowed within a moving window of time.
If you can (the message is not "personalized") it is best to send one message to multiple recipients, rather than many messages, each to one recipient. Do that by perhaps putting your own e-mail address in the To field, and then Bccing the whole of the list of recipients in one go. You'll have to check your mail command for how to do that.

Where are received mails by Mailcatcher stored?

I have installed postfix on my Mac with and changed the following parameters :
mydestination =
relayhost = 127.0.0.1:1025
I've modified mydestination to be blank so that whoever the mail is sent to like bellow in the Terminal it necessarily goes through the relayhost (even if it's sent to #localhost) and I can see it appear in my web-browser in Mailcatcher's tab :
echo "Body test" | mail -s "Subject test" test#dev.local
But here's the thing, when I receive the mail I do receive it instantly with the built-in websockets but if I do reload the page localhost:1080, emails are still there, meaning they must be stored somewhere.
After searching I found that the following URL redirects to a .json that contains received mails that are print out in Mailcatcher's tab :
localhost:1080/messages
But if I do a ls -l in my webroot directory, there's no messages.json that appears. And when you do click on the "Quit" button in Mailcatcher's, then relaunch it by doing mailcatcher and opening again localhost:1080 mails have disappeared...
I don't understand, is there a file that is deleted when you do click "Quit" and that I might haven't seen ?
Thanks for your help !
If you check the source on GitHub you will find something like this SQLite3::Database.new(":memory:", :type_translation => true).tap do |db| in mail.rb.
You may not have noticed, but MailCatcher uses SQLite, and the above tells you that it is configured to run in memory. So, when turning off MailCatcher all the rows that are contained in this database are lost.

How do I send an email using awk to a list of email addresses in a text file?

If I have a text file with a list of email addresses, how can I go through the list and send an email to each of those email addresses with a text file as the message.
I.e. I want to take in an email as a variable so I can execute this command:
mail -s "Welcome" email#address.com < welcome.txt
for example you have a mails_addresses.txt file with one address per line like that:
email1#mail.com
email2#mail.com
email3#mail.com
In case you have another complex structure which you need to parse with for example awk you should to show it us.
So you need just to write a loop which will read it and send it to mail command:
while read MAIL
do
mail -s "Welcome" "$MAIL" < welcome.txt
done < mails_addresses.txt
You can do this even without awk:
cat users-list | while read addr
do
mail -s "Welcome" "$addr" < welcome.txt
done

Resources