Mailinglist Archive: opensuse (1690 mails)

< Previous Next >
Re: [opensuse] Metasend
On 11/5/2011 9:29 AM, Mark Misulich wrote:
Hi,
a couple of weeks ago I posted asking for some help with a spurious
email that I was receiving when I sent out emails to a group for which I
write a newsletter.

One of the members of the list was kind enough to respond off list and
send me a metasend script that he uses, recommending to use it instead
of my current method of mailing. Here is the script:

metasend -b -e 7bit -t $DEST \
-s $SUBJECT \
-F $FROM \
-m "text/plain" -f $TEXTFILE \
-n \
-S 10000000 \
-m "application/pdf;name=\"${PDFFILE}\"" \
-f ${PDFFILE} \
-D ${PDFFILE}
sleep 5
done


I didn't exactly know how to use the script so I wrote back to seek some
clarification, and of course my attempt to figure it out was wrong. The
response I got was less than helpful, and I am still left in the dark as
to how to use the script. So I thought that it would be more profitable
to seek advice here on the list regarding how to use this list.

I think that in place of each of the capitalized parts of the script I
need to insert something, so here is my best guess and I hope that the
list members will correct me.

DEST - I think that I have to make up and insert a file into the script
with each of the email addresses of the mail list members, like

abernathycool@xxxxxxxxxxxxx Abernathy Cool

suzytalker@xxxxxxxxxxxxxx Suzy Talker

jonathantrakes@xxxxxxxxxxxx Jonathan Trakes

I don't think that I can point to the file from within the script, as if
the mail list file was stored on the computer in a different file. I
think that it has to be a part of the script.


SUBJECT - Just replace this with something like "Monthly Newsletter"

FROM - replace this with my email address

TEXTFILE - Not sure what this one is for, unless it is something to
appear in the body of the email, like: This is your monthly newsletter!

PDFFILE - Not sure what to do with this one, I think I have to insert
the whole pdf file of the newsletter here but am not sure how to do
that.


Well, as you can probably tell from my questions, I haven't caught on to
this yet. So I hope that your answers will be simple and explanatory.

Thanks,
Mark


You have it pretty close.

Create a file with the email addresses and associated human-readable names.
Use this format:
Brian K. White <brian@xxxxxxxxx>
Or, when you don't have the human readable name you can put just the email on a line by itself with no <> or anything else
brian@xxxxxxxxx
You can put almost anything you want at the beginning of the line for the human-readable name, followed by the email address inside of <>

Abernathy Cool <abernathycool@xxxxxxxxxxxxx>
Suzy Talker <suzytalker@xxxxxxxxxxxxxx>
Jonothan Trakes <jonathantrakes@xxxxxxxxxxxx>
Some user with long name jr. the third esquire <user@xxxxxxxxxxxxx>

Don't put quotes in the human readable names like
Jack "the Jack" Jackson <jack@xxxxxxx>"
It would require more and fancier scripting to handle that so it's easier to just say, don't do it, it'll screw up the next part since the script that reads this is going to be intentionally simple.
The script can be improved later to improve the handling of these lines to handle things like that.
You can leave single quotes if there are any, like
Jack O'Hare <johare@xxxxxxx>

Name that file newsletter_list_members.txt

Create a file with some boilerplate body text like:
"Attached is this weeks newsletter."

Name it newsletter_mail_body.txt

Create a new file named newsletter_send_all.sh

Write this script in it, don't include the ----------
------------
#!/bin/bash
# newsletter_send_all.sh
# Sends the newsletter with pdf from argument #1 attached,
# to all addresses found in newsletter_list_members.txt

# Configuration
SUBJECT="[Newsletter] Foo Newsletter for `date`"
FROM_ADDR="Newsletter Admin <admin@xxxxxxxxxxxxxx>"
MAIL_BODY_FILE=newsletter_mail_body.txt

##############################

[[ -e $1 ]] || { echo "usage: ${0##*/} file.pdf" ; exit 1 ; }
PDF_FILE=$1

echo "Sending newsletter to:

DONE=false
until $DONE
do
read DEST || DONE=true
echo -en "${DEST}\t\t..."
metasend -b -e 7bit -t "$DEST" \
-s "$SUBJECT" \
-F "$FROM" \
-m "text/plain" -f "$MAIL_BODY_FILE" \
-n \
-S 10000000 \
-m "application/pdf;name=\"${PDF_FILE##*/}\"" \
-f "$PDF_FILE" \
-D "${PDF_FILE##*/}" && echo "OK." || echo "FAILED!"
done
-------------

Then create the newsletter pdf somewhere on the same machine.

Then run the script like this:

sh newsletter_send_all.sh /path/to/newsletter.pdf

Everyone else, there is a reason I used the separate DONE variable and didn't use "while read ..."

There are numerous, heck countless, improvements and enhancements that could be made to this to make it handle various corner cases more robustly and make various things more configurable and dynamic. You have to start somewhere so this is intentionally almost as simple as possible while still doing the necessary job.

"man metasend" to see what the different metasend command line arguments are doing.

"man bash" to try to figure out what some of the odd looking syntax means.


$1 is the argument given on the command line, it will be /path/to/file.pdf. It's like that so that you can have each newsletter have a different file name with the date in it without having to edit the script or without having to keep overwriting the same file every time with the latest newsletter.

$PDF_FILE is filled with a copy of $1 instead of using $1 directly for a few different reasons but mostly just to make the script easier to read and work on in the future.

${VARIABLE} is the same as $VARIABLE, except the {} are an optional syntax to disambiguate the letters that are supposed to be part of the variable name from any other text when you have to embed the variable in other text with no spaces. The curly braces are also needed whenever you want to use any of the advanced forms of variable expansion such as:

${VARIABLE##...} is a special form variable expansion where only part of the variable's contents will be output, according to the stuff after the ##.

${VARIABLE##*/} is a particular common and handy use of above that essentially does the same thing as the "basename" command. It means to skip everything up to and including the last "/" character, and only output whatever is left. It doesn't modify the variable contents, it just modifies how those contents are printed that one time. So:
$ TT=/path/to/some/thing
$ echo "$TT"
/path/to/some/thing
$ echo "${TT##*/}"
thing

I put that in there so that the recipients emails don't say /home/yourself/newsletter/november_07.pdf in them. Instead it will only say "november_07.pdf" in their "save file" dialogs.

Use the metasend command directly, manually, to send yourself test files, and tweak the command and the contents of the script and such before you use the script to send to lots of people. And/or, use the script but just put yourself in the list members txt file at first until you really like the way the emails look when you get them. What happens when you click the attachments, what happens when you try to "reply" to the mail, what does the From: and Subject: look like, etc.

I put "[Newsletter] " at the beginning of the subject for the same reason most mail lists have a tag like that in the subject, so recipients can make mail filter rules to put these mails into their own folder automatically on receipt.

The structure of the script intentionally places the parts you're intended to customize and change once in a while at the top and separated from the rest to make it easy to do periodically without having to worry about screwing up the more complicated parts below.

The `date` in the subject is single back-ticks, not regular single-quotes. It will place the current date and time in that spot.

The && and || are a compact syntax for if/then/else/fi

somecommand && echo it worked || echo it failed

is the same as
if somecommand
then
echo it worked
else
echo it failed
fi

--
bkw
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >
References