Why do Period will be ignored at the beginning of a sentence in SendEmail on Linux - linux

I want to use command line to send an email on Linux so I choose sendEmail (a lightweight, command line SMTP email client). However, I find Period (.) at the beginning of a sentence will be ignored and it really confused me.
-m MESSAGE message body
My command:
sendEmail -f sender#example.com -t receiver#example.com -u "Test mail" -s smtp.example.com -xu sender#example.com -xp sender_password -m ".Hello\n..Hello\nHello.world" -o tls=no
What I want to display is:
.Hello
..Hello
Hello.world
But the result is:
Hello
.Hello
Hello.world
Thanks a million.

This is a bug in the sendEmail client. In SMTP a line containing nothing else but a single period . is used to indicate the end of the message (DATA segment in SMTP). To avoid unintended transmission termination if a message contains a line with a single period, on all lines starting with a period an extra period has to be added before the message goes onto the wire; and removed upon receive. It's the task of a proper SMTP client to take care of this. It's clearly a faulty behavior of the client.
To get around the bug, add an extra period.
For details see RFC5321, sections 4.1.1.4 and 4.5.4.

Related

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.

How to read continuous log file from last read line | Linux Shell

Platform: RHEL7
Situation:
A JMeter report file is being appended with new results every 5 minutes by crontab script
Another awk script looks for response time greater than 500ms and sends email alerts
Problem Statement:
The requirement is to scan only newly added lines in the report file.
Presently, the awk script is reading the complete report every time
and sends alerts even for older events. awk -F "," '$4 != 200 || $14>
500' results.jtl
Good-to-Have if the awk script can read from the end of the file up to line read last time. This shall help in creating an alert for the latest event first.
Any suggestion shall be a great help.
Any reason for not using:
Duration Assertion: for failing samples which response times are over 500 ms
If Controller: with condition ${JMeterThread.last_sample_ok} which checks whether last sampler is successful or not
SMTP Request Sampler: to send an email when there is a failure

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.

Linux shell script to remove 2 day old frozen emails from exim queue

I want to put shell script under the cron job which will do following:
1) Removes 2 days old email messages which are in the Exim queue and are bounced/frozen messages, which won't be delivered. Script must not remove messages which are legitimate and are just waiting their time to be delivered.
2) Removes messages which are from invalid sender like null or <> and / or sent to invalid recipient nobody or <>
Thanks a lot.
exiqgrep is your friend! You can easily find queue items matching certain criteria and pipe the found message-id:s to a remove command. E.g:
exiqgrep -z -o 172800 -i | xargs -r exim -Mrm
which translates as follows: find queue items (exiqgrep) that are frozen (-z) and older than two days (-o 172800) and output their message id:s (-i) to xargs that runs only if getting any input (-r) telling exim to remove (-Mrm) the items with given message id:s.
Null (or <>) senders are certainly not invalid! Bounces and other (non-)delivery reports are typically sent from a null address in order to avoid infinite loops in case the bounce is not deliverable. However if you have lots of these on the queue and they stay there for long (e.g. if you are trying to bounce spam sent from fake addresses) you can certainly clean them up too. For example:
exiqgrep -o 86400 -f '<>' -i | xargs -r exim -Mrm
which finds queue items older than one day with a null sender and deletes them.
EDIT: you could also set the following option in your exim.conf to automatically remove frozen bounces after two days:
ignore_bounce_errors_after = 2d

Create serial mail on linux commandline

I would like to generate serial emails on the linux commandline. Assume I have a file indicating mail address, subject and message text in columns on separate lines for each recipient. I.e.
recipient1#mail.com subject1 text1
recipient2#mail.com subject2 text2
...
The script should use standard commands as I intend to send it to colleagues who should create some emails for me.
The loop over the lines could be with xargs ... Can I use the commandline tool mail?
It is important that the mails are not send immediately. Ideally it creates files for import in the users preferred mail client. So that senders can check the mails before they submit.
I also would like to be able to add attachments to the Mails.
I tried e.g.
function mail_kmail {
kmail -s "$2" --body "$3" --attach "$4" --composer "$1"
}
function mail_thunderbird {
thunderbird -compose "to='$1',subject='$2',body='$3',attachment='$4'"
}
and reading the input data from file with
while read recipient subject body attach $file
do
mail_kmail "$recipient" "$subject" "$body" "$attach";
done
but this will work only if my colleagues installed and set up either of these mail clients.
I found this (closed) related question:
How can i send automated email in linux? .
You can use mutt to send the emails, here is an example:
echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient#domain.com
Since it's hard to know what you are trying to achieving here, you can even create a configuration file to be used, but you'll to investigate more or give more details about your use case.

Resources