You are not logged in.
Hello everyone,
I am looking for a hint on how to do the following:
I have a bunch of prepared mails (~300). They're one file each, including header and body. What I need to do now seems relatively simple - I want to send them out. I have been advised to use
mailto do so, but I can't seem to figure out how to do this. I studied the manpage looking for a way to give mail a file as a argument and found
-q file Start the message with the contents of the specified file. May be given in send mode only.However, it returns
mail -q myfile
Send options without primary recipient specified.So apparently, the contents of the file are really just used for the mail body, not header and body.
Is there any way to make mail send my file "as is"?
Thank you in adavance!
Offline
Should be easy enough with a bit of scripting, can you post an example file so we can see the exact format please.
Offline
Yes, of course. The mails look like this:
Content-Type: multipart/encrypted;
protocol="application/pgp-encrypted";
boundary="----------=_1395064062-6308-209"
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
X-Mailer: MIME-tools 5.503 (Entity 5.503)
Subject: $SUBJECT
To: $RECEIVER
From: $SENDER
Sender: $SENDER
User-Agent: $MYUSERAGENT
This is a multi-part message in MIME format...
------------=_1395064062-6308-209
Content-Type: application/pgp-encrypted; name="myname.msg"
Content-Disposition: attachment; filename="myname.msg"
Content-Transfer-Encoding: 7bit
Version: 1
------------=_1395064062-6308-209
Content-Type: application/octet-stream; name="msg.asc"
Content-Disposition: inline; filename="msg.asc"
Content-Transfer-Encoding: 7bit
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.12 (GNU/Linux)
-- crypted content --
-----END PGP MESSAGE-----
------------=_1395064062-6308-209--Offline
I studied the manpage looking for a way to give mail a file as a argument and found
-q file Start the message with the contents of the specified file. May be given in send mode only.
That does say "start ... with" so you probably still end up in an editor. It might work better to use input redirection to feed the file to mail.
So apparently, the contents of the file are really just used for the mail body, not header and body.
The file is used as the message text (for the DATA command in SMTP), which includes both header and body. It does not parse this message text to extract a recipient (which, in SMTP, is given separately with the RCPT command). You have to pass the recipient as an argument to mail. According to the man page, it accepts comma-separated lists and it can handle full specifications including both names and addresses, so you can probably extract $RECEIVER in your script and pass this to mail without any further processing (and similarly for $SENDER and $SUBJECT, unless these are the same for all messages).
Or perhaps somebody can suggest a way to make mail or a related tool perform this extraction for you.
Offline
I think sendmail would be better for pre-generated emails like this, assuming you have it installed. You would still have to extract $RECEIVER, but you could then (for each file) cat each file and pipe it to sendmail, e.g.
cat mailfile | sendmail "${RECEIVER}"Otherwise (if you have to use mail/mailx) then as Raynman says, you'll have to extract $SENDER and $SUBJECT as well, but I'm not sure how the sent email will look with extra To/From/Etc fields.
Offline
Maybe I was also partly thinking of sendmail. I'm actually not that familiar with the mail command and sendmail is probably better for this job, because you don't want mail to make changes to the contents of the file.
But both tools have a -t option (which I overlooked in mail's man page at first) to read the recipient from the headers in the mail, so try
sendmail -t < mailfileOffline
I didn't know about the -t flag, that's definitely the better option. ![]()
Offline