here I'm working on sun Solaris 10, I have tried before to send a normal email with and without attach and its worked fine with me , but now I'm trying to cat-file element and send attach in the same email but it does not work
this is my result.txt file body :
Total Number of Files = 8
Total Number of Fixed Files = 4
Total Number of Notification Files = 4
Total Number of Courrpted Files = 0
Total Execution Time = 3 Seconds.
this is my data.txt file body :
Notification Files :
file number 1
file number 2
unix command :
RECEIPIENTS="mm#gmail.com"
SUBJECT="!! testtt !!"
(cat Results.txt ; uuencode Data.txt Data.txt) | mailx -s "$SUBJECT" -c mm#gmail.com,dd#gmail.com -r zz#gmail.com $RECEIPIENTS
this is what i got after sending the email :
Total Number of Files = 8
Total Number of Fixed Files = 4
Total Number of Notification Files = 4
Total Number of Courrpted Files = 0
Total Execution Time = 3 Seconds.
begin 777 Data
M#0I.;W1I9FEC871I;VX#1FEL97,#.B -"#T*,2U#1$M(34LU2D]21DPP,#0R
M,#T*,BU#1$Q454]-2D]21DPP-S$Q- T*,RU#1$Q454]-2D]21DPP-S$Q-#T* M-"U#1$Q604Q-2D]21DPP-#0U, T*#0I&:7AE9"!&:6QE<R Z( T*#0HQ+4-$ M051'2SE*3U)&3# P,3$T#0HR+4-$051'2SE*3U)&3# P,3$U#0HS+4-$0TA.
C0U5*3U)&3#,Q.3DT#0HT+4-$0TA.0U5*3U)&3#,Q.3DU#0HU
end
note: if I use echo or echo -e or attach the file with uuencode without cat its worked fine, the problem only when I use cat with uuencode
There was a time in the last millennium when uuencode made sense, but you really should be using MIME instead in this day and age.
Here is a simple Python 3 script which combines a message from standard input with an attachment into a valid RFC822 message which you can send with sendmail or similar. It is rather closely based on the Python documentation's examples.
#!/usr/bin/env python3
from email.message import EmailMessage
import sys
msg = EmailMessage()
msg['From'] = sys.argv[1]
msg['To'] = sys.argv[2]
msg['Subject'] = sys.argv[3]
# Don't mess with the preamble, the documentation is wrong to suggest you do
msg.set_content(''.join([line for line in sys.stdin]))
with open(sys.argv[4], 'r') as attachment:
msg.add_attachment(attachment.read(), maintype='text', subtype='plain')
print(msg.as_string())
To use this in your example,
# If `sendmail` is not in your `PATH`, maybe add it.
# For example, if you have it in `/usr/lib/sendmail`
# and `/usr/libĀ“ is not in your `PATH`, you can add it with
#PATH=$PATH:/usr/lib
# Don't use upper case for private variables; check spelling of "recipients"
# To demo an example of sending to multiple addresses, adds a second recipient
recipients="mm#gmail.com,another#example.com"
subject="!! testtt !!"
python3 path/to/script.py "zz#gmail.com" "$recipients" "$subject" Data.txt <Results.txt |
sendmail -oi -t
You can leave out the pipe to sendmail to see what the message looks like. Instead of uuencode smack dab in the message body, it creates a multipart MIME message with two parts, one of which is inline and contains the text from standard input, and another which is properly tagged as an attachment. It's slightly bulky, but I'm including an example here just to show you.
From: zz#gmail.com
To: mm#gmail.com,another#example.com
Subject: !! testtt !!
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============2189027902917283968=="
--===============2189027902917283968==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Total Number of Files = 8
Total Number of Fixed Files = 4
Total Number of Notification Files = 4
Total Number of Courrpted Files = 0
Total Execution Time = 3 Seconds.
--===============2189027902917283968==
Content-Type: text/plain
Content-Transfer-Encoding: base64
MIME-Version: 1.0
Content-Disposition: attachment
Tm90aWZpY2F0aW9uIEZpbGVzIDogCmZpbGUgbnVtYmVyIDEKZmlsZSBudW1iZXIgMgo=
--===============2189027902917283968==--
The attachment is rather needlessly base64-encoded in this particular example; you can tweak the Python code if you absolutely need it to be human-readable (but then neither was the uuencode).
(Also, no idea why the body part has a separate MIME-Version: header -- that seems like a bug.)
Related
I tried to verify an email address using SMTP for all mailboxes it's working fine except for Yahoo email ID. While connecting telnet I got errors like "556 5.7.5 Invalid RFC missing body".
Welcome to Stack Overflow, Jayashree.
The error message you are receiving is related to your test email not having a body part. The body part begins immediately after 2 <CRLF><CRLF> following the Content-Transfer-Encoding.
It begins at Good morning. and ends at P | 999.555.1234
Below is a complete example of a properly formatted text/plain email.
To: "Jane Doe" <jane#example1.com>
From: "John Doe" <john#example1.com>
Subject: A text/plain email
MIME-Version: 1.0 (Created with SublimeText 3)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Good morning.
This is a message in text/plain format.
It contains text/plain.
It contains no base64 inline images or attachments.
Each line is no more than 76 characters in length.
Please reach out if you have any questions.
Thank you,
John Doe
SENIOR DEVELOPER
XYZ Solutions Inc.
P | 999.555.1234
I have a collection of 338 .log files. These are just basic text files and no two files have the same file name (but all file names start with "rrm-"). Here is an example of the data they contain:
Receiving message #1 : OK (4480 bytes)
From: <djerry#domain.com>
Subject: 2-303-468-02
Message-ID: <PRODVAPP21XvCsLCXPI0035acee#prod.domain.com>
Forwarding to "Some User" <someuser#somedomain.com> : OK
I need a script that will open each file one at a time, parse only the "From:" lines (could be 10, could be 1000s) to extract only the email address between the < and > characters, and write the output to a single text file, one email address per line. The rest of the data I don't care about. I also don't care about validating the email addresses. The resulting text file would look like this:
djerry#domain.com
bob#domain.com
tom#blah.com
jerry#yada.com
I'm not a programmer, I only know how to break things when I try. I don't even know what software / utility I would need to use for this. I'm using a Windows 10 computer. So maybe a Powershell script? Sorry for such a n00b question, I really hate feeling stupid for not knowing how to or being able to google for a simple solution. Appreciate any help!
Try the following:
Select-String -Pattern '^From: .*?<(.+?)>' -Path rrm-* |
ForEach-Object { $_.Matches.Groups[1].Value } > output.txt
^From: .*?<(.+?)> is a regex (regular expression) that finds lines that start with From: and captures what follows between < and >.
The .*? part is to account for an (optional) actual name preceding the <...>-enclosed email address, as is common; e.g, "Dana Jerry" <djerry#domain.com>. Thanks, TheMadTechnician
$_.Matches.Groups[1].Value retrieves what was captured.
> output.txt saves the results to a file.
For a couple of days, I've been trying to write procmail script.
I want to forward messages, and inject some text into message contents.
What I want to accomplish :
someone send me e-mail, with word "weather" in the subject
email is forwarded to address "mymail#somedomain.com"
every forwarded email gets some added text in contents
But so far, no success.
In .procmail.log, there's a message "procmail: Missing action"
SHELL=/bin/bash
VERBOSE=off
LOGFILE=/home/test/.procmail.log
LOGDATE_=`/bin/date +%Y-%m-%d`
:0
* ^Subject:.*weather
:0 bfw
| echo "This is injected text" ; echo "" ; cat
:0 c
! mymail#somedomain.com
When I looked into email source, I saw that text is injected.
But the place is wrong ...
Take a look:
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="------------148F3F0AD3D65DD3F3498ACA"
Content-Language: pl
Status:
X-EsetId: 37303A29AA1D9F60667466
This is injected text
This is a multi-part message in MIME format.
--------------148F3F0AD3D65DD3F3498ACA
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
CONTENT CONTENT CONTENT
*********************************************************
Injected text should be placed, where content is. Now it is above ...
You don't explain your code, but it looks like that you are attempting to use multiple actions under a single condition. Use braces for that.
:0
* ^Subject:.*weather
{
:0 bfw
| echo "This is injected text" ; echo "" ; cat
:0 c
! mymail#somedomain.com
}
Just to summarize, every recipe must have a header line (the :0 and possible flags) and an action. The conditions are optional, and there can be more than one. A block of further recipes is one form of action so that satisfies these requirements (the other action types are saving to a folder, piping to a command, or forwarding to an email address).
To inject text at the top of the first MIME body part of a multipart message, you need to do some MIME parsing. Procmail unfortunately has no explicit support for MIME, but if you know that the incoming message will always have a particular structure, you might get away with something fairly simple.
:0
* ^Subject:.*weather
{
:0fbw
* ^Mime-version: 1\.0
* ^Content-type: multipart/
| awk '/^Content-type: text\/plain;/&&!s {n=s=1} \
n&&/^$/{n=0; p=1} \
1; \
p{ print "This is injected text.\n"; p=0 }'
:0 c
! mymail#somedomain.com
}
The body (which contains all the MIME body parts, with their headers and everything) is passed to a simple Awk script, which finds the first empty line after (what we optimistically assume is) the first text/plain MIME body part header, and injects the text there. (Awk is case-sensitive, so the regex text might need to be adapted or generalized, and I have assumed the whitespace in the input message is completely regular. For a production system, these simplifying assumptions are unrealistic.)
If you need full MIME support (for example, the input message may or may not be multipart, or contain nested multiparts), my recommendation would be to write the injection code in some modern script language with proper MIME support libraries; Python would be my pick, though it is still (even after the email library update in 3.6) is slightly cumbersome and clumsy.
I would like to send message from Unix server. I use command 'mail':
echo "MESSAGE_BODY" | mail -s "MESSAGE_TITLE" somebody#gmail.com
It's ok with it.
After that I want to send message with different colors. I tried this command:
echo "<font color="red">MESSAGE_BODY</font>" | mail -s "MESSAGE_TITLE" somebody#gmail.com
But it didn't help me. How to use colors ?
There have already been a "one-liner" that have posted the correct answer.
I do still feel that it's better to post how and why.
The reason why you can't just echo HTML code directly into your mail is that the receiver (Client) don't know how to display it. So it will most likely just fallback to clear text and all you would see was your HTML code when viewing the message.
What you need, is to tell the client that the content of your message is composed in HTML. You do this by adding the correct MIME header to the message.
Content-Type: text/html; charset=UTF-8
MIME-Version: 1.0
Notice you can also set charset information.
The MIME version is there for better compatibility also some SMTP servers will give you a higher spam score if you don't obey the RFC :)
But with these headers set now all "BODY" content will be treated like HTML content.
I don't just want to provide you with a "one-liner" I think showing more in a script is better to make it easier to read.
So how about this
(
echo "From: my#email.tld";
echo "To: some#email.tld";
echo "Subject: Test html mail";
echo "Content-Type: text/html";
echo "MIME-Version: 1.0";
echo "";
echo "<strong>Testing</strong><br><font color=\"blue\">I'm Blue :)</font>";
) | sendmail -t
Well technically it's still a one-liner :) But it just looks nicer and you can see what's going on!
Bonus information
If you want to have both HTML and TEXT bodies you need to look into Multipart content type bodies. I have included an example but you would properly need to read up on this if you don't know much about multipart types.
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="--0001boundary text--"
--0001boundary text--
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
The TEXT body goes here
--0001boundary text--
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
<strong>HTML code goes here</strong>
--0001boundary text--
As you can see it's no longer some simple mail body.
But I thought I wanted to show you how it was done in case you wanted to give it a go.
echo "<font color="green">Message body</font>" | mail -s "$(echo -e "Message title\nContent-Type: text/html")" somebody#gmail.com
I'm using getmail + maildrop + mutt + msmtp chain with messages stored in Maildir. Very big inbox bothers me, so i wanted to organize mail by date like that:
Maildir
|-2010.11->all messages with "Date: *, * Nov 2010 *"
|-2010.12->same as above...
|-2011.01
`-2011.02
I've googled much and read about mailfilter language, but still it is hard for me to write such filter. Maildrop's mailing list archives has almost nothing on this (as far as i scanned through it). There is some semi-solution on https://unix.stackexchange.com/questions/3092/organize-email-by-date-using-procmail-or-maildrop, but i don't like it, because i want to use "Date:" header and i want to sort by month like "YEAR.MONTH" in digits.
Any help, thoughts, links, materials will be appreciated.
Using mostly man pages, I came up with the following solution for use on Ubuntu 10.04. Create a mailfilter file called, for example, mailfilter-archive with the following content:
DEFAULT="$HOME/mail-archive"
MAILDIR="$DEFAULT"
# Uncomment the following to get logging output
#logfile $HOME/tmp/maildrop-archive.log
# Create maildir folder if it does not exist
`[ -d $DEFAULT ] || maildirmake $DEFAULT`
if (/^date:\s+(.+)$/)
{
datefile=`date -d "$MATCH1" +%Y-%m`
to $DEFAULT/$datefile
}
# In case the message is missing a date header, send it to a default mail file
to $DEFAULT/inbox
This uses the date command, taking the date header content as input (assuming it is in RFC-2822 format) and producing a formatted date to use as the mail file name.
Then execute the following on existing mail files to archive your messages:
cat mail1 mail2 mail3 mail4 | reformail -s maildrop mailfilter-archive
If the mail-archive contents look good, you could remove the mail1, mail2, mail3, mail4, etc. mail files.