[opensuse] Metasend
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@jpmussels.com Abernathy Cool suzytalker@roadrunner.net Suzy Talker jonathantrakes@scommand.com 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 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Sat, 5 Nov 2011 23:59:16 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 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.
What you have is a fragment of a script - this is not a complete shell script. I'd suggest you read a) the metasend man page, to understand what the above fragment is doing, and b) a tuturial on shell scripting for your preferred shell (be it bash, zsh, csh or whatever) or get to know something like python or ruby (either of which I'm pretty sure could handle this easily).
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@jpmussels.com Abernathy Cool
suzytalker@roadrunner.net Suzy Talker
jonathantrakes@scommand.com 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.
The ${XXXX} are names of variables that you have to define at the beginning of the script. For example: DEST="some-recipient@some-server.domain" SUBJECT="Monthly Newsletter" FROM="you@your.isp.domain" TEXTFILE="/path/to/textfile" PDFFILE="/path/to/pdffile" You could hard code these in the script, or you could pass them as command- line parameters. I suggest you consult a tutorial on scripting for your specific shell (bash, csh, zsh etc.) to see how to do this. This of course assumes that the script is being called once for each email address on the list. An easier way would be to source a file with a list of all the email addresses, then parse that file one line at a time in a conditional loop until you reach EOF, updating DEST and re-running the above fragment until the last email has been sent. Shell scripting isn't that hard once you've played with it a few times. There are plenty of good online resources that google will turn up for you but some are better than others - YMMV. HTH, Rodney. -- =================================================== Rodney Baker VK5ZTV rodney.baker@iinet.net.au =================================================== -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Rodney Baker said the following on 11/05/2011 10:31 AM:
What you have is a fragment of a script - this is not a complete shell script.
I told him that when I sent it to him bask on 10/16/2001
I'd suggest you read a) the metasend man page, to understand what the above fragment is doing,
I suggested that to him as well. Man pages are an important part of comprehension. If you don't read and understand them you are unlikely to understand how to use the command.
and b) a tuturial on shell scripting for your preferred shell (be it bash, zsh, csh or whatever)
And I suggested that as well.
I don't think that I can point to the file from within the script,
You can, I showed him how.
as if the mail list file was stored on the computer in a different file.
I told him that as well, I even suggested the format, address followed by names I explained that the above was the 'inner loop' and that he needed something external to it that did: cat addressfile | while read DEST REALNAME do ...
The ${XXXX} are names of variables that you have to define at the beginning of the script. For example:
I told home that too, and explained and illustrated just as you have done but rather more ...
DEST="some-recipient@some-server.domain" SUBJECT="Monthly Newsletter" FROM="you@your.isp.domain" TEXTFILE="/path/to/textfile" PDFFILE="/path/to/pdffile"
Actually I suggested ------------------------------ #! /bin/sh cd $HOME/SkiMailManagement ADDRESSFILE=${ADDRESSFILE-skipatrolemailaddresslist} SUBJECT=${SUBJECT-"Newsletter for $(date %B %Y)"} FROM=${FROM-"munguanaweza@embarqmail.com"} TEXTFILE=${TEXTFILE-./newsletters/$(date %Y/%b).txt} PDFFILE=${PDFFILE-./newsletters/$(date %Y/%b).pdf} You can see that there are few assumptions. First, that this is a directory of its own where the address list and other stuff live. Second that there is a subdirectory with the newsletters. Third, that they are "by month". Fourth that they are available both as text and PDF. OOPS! Not everyone does that, eh? So the TEXTFILE should be set to a plain text file that says "Please see the attached PDF file". Having things set like this with the shell variables allows for this flexibility.
An easier way would be to source a file with a list of all the email addresses, then parse that file one line at a time in a conditional loop until you reach EOF, updating DEST and re-running the above fragment until the last email has been sent.
That depends on whether you see the fragment as being all of the script or having the 'while' in the script. The lists I maintain this for it is inside the script.
Shell scripting isn't that hard once you've played with it a few times. There are plenty of good online resources that google will turn up for you but some are better than others - YMMV.
I think his real problem is that he doesn't get shell scripting and variables. Once upon a time UNIX ran in less than 56K so there was more reliance on scripts as opposed to binaries. That's where I leant, machines that had lots and lots of scripts to do what we do with binaries these days. Much more 'visibility'. I also suggested he read http://www.shelldorado.com/scripts/cmds/sendfile which is a much simpler but well scripted example of using metasend. -- People who make no mistakes do not usually make anything. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 11/5/2011 3:02 PM, Anton Aylward wrote:
Rodney Baker said the following on 11/05/2011 10:31 AM:
What you have is a fragment of a script - this is not a complete shell script.
I told him that when I sent it to him bask on 10/16/2001
I'd suggest you read a) the metasend man page, to understand what the above fragment is doing,
I suggested that to him as well. Man pages are an important part of comprehension. If you don't read and understand them you are unlikely to understand how to use the command.
and b) a tuturial on shell scripting for your preferred shell (be it bash, zsh, csh or whatever)
And I suggested that as well.
I don't think that I can point to the file from within the script,
You can, I showed him how.
as if the mail list file was stored on the computer in a different file.
I told him that as well, I even suggested the format, address followed by names
I explained that the above was the 'inner loop' and that he needed something external to it that did:
cat addressfile | while read DEST REALNAME do ...
The ${XXXX} are names of variables that you have to define at the beginning of the script. For example:
I told home that too, and explained and illustrated just as you have done but rather more ...
DEST="some-recipient@some-server.domain" SUBJECT="Monthly Newsletter" FROM="you@your.isp.domain" TEXTFILE="/path/to/textfile" PDFFILE="/path/to/pdffile"
Actually I suggested
------------------------------ #! /bin/sh
cd $HOME/SkiMailManagement
ADDRESSFILE=${ADDRESSFILE-skipatrolemailaddresslist} SUBJECT=${SUBJECT-"Newsletter for $(date %B %Y)"} FROM=${FROM-"munguanaweza@embarqmail.com"}
TEXTFILE=${TEXTFILE-./newsletters/$(date %Y/%b).txt} PDFFILE=${PDFFILE-./newsletters/$(date %Y/%b).pdf}
You can see that there are few assumptions. First, that this is a directory of its own where the address list and other stuff live. Second that there is a subdirectory with the newsletters. Third, that they are "by month". Fourth that they are available both as text and PDF.
OOPS! Not everyone does that, eh? So the TEXTFILE should be set to a plain text file that says "Please see the attached PDF file".
Having things set like this with the shell variables allows for this flexibility.
An easier way would be to source a file with a list of all the email addresses, then parse that file one line at a time in a conditional loop until you reach EOF, updating DEST and re-running the above fragment until the last email has been sent.
That depends on whether you see the fragment as being all of the script or having the 'while' in the script.
The lists I maintain this for it is inside the script.
Shell scripting isn't that hard once you've played with it a few times. There are plenty of good online resources that google will turn up for you but some are better than others - YMMV.
I think his real problem is that he doesn't get shell scripting and variables.
Once upon a time UNIX ran in less than 56K so there was more reliance on scripts as opposed to binaries. That's where I leant, machines that had lots and lots of scripts to do what we do with binaries these days. Much more 'visibility'.
I also suggested he read http://www.shelldorado.com/scripts/cmds/sendfile which is a much simpler but well scripted example of using metasend.
I wish I'd read this before I went and spent all the time writing my last post! headsmak. -- bkw -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Sun, 2011-11-06 at 22:01 -0500, Brian K. White wrote:
I wish I'd read this before I went and spent all the time writing my last post! headsmak.
-- bkw
Hi, thanks for taking the time to write your reply, the info is very helpful to me. Mark -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Sun, 2011-11-06 at 01:01 +1030, Rodney Baker wrote:
On Sat, 5 Nov 2011 23:59:16 Mark Misulich wrote:
What you have is a fragment of a script - this is not a complete shell script. I'd suggest you read a) the metasend man page, to understand what the above fragment is doing, and b) a tuturial on shell scripting for your preferred shell (be it bash, zsh, csh or whatever) or get to know something like python or ruby (either of which I'm pretty sure could handle this easily).
The ${XXXX} are names of variables that you have to define at the beginning of the script. For example:
DEST="some-recipient@some-server.domain" SUBJECT="Monthly Newsletter" FROM="you@your.isp.domain" TEXTFILE="/path/to/textfile" PDFFILE="/path/to/pdffile"
You could hard code these in the script, or you could pass them as command- line parameters. I suggest you consult a tutorial on scripting for your specific shell (bash, csh, zsh etc.) to see how to do this.
This of course assumes that the script is being called once for each email address on the list. An easier way would be to source a file with a list of all the email addresses, then parse that file one line at a time in a conditional loop until you reach EOF, updating DEST and re-running the above fragment until the last email has been sent.
Shell scripting isn't that hard once you've played with it a few times. There are plenty of good online resources that google will turn up for you but some are better than others - YMMV.
HTH, Rodney.
-- =================================================== Rodney Baker VK5ZTV rodney.baker@iinet.net.au ===================================================
Hi, thanks for the helpful reply. I can't make any pretense about knowing anything about shell scripting, but this got me pointed in the right direction to learn it. Mark -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
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@jpmussels.com Abernathy Cool
suzytalker@roadrunner.net Suzy Talker
jonathantrakes@scommand.com 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@aljex.com> 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@aljex.com 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@jpmussels.com> Suzy Talker <suzytalker@roadrunner.net> Jonothan Trakes <jonathantrakes@scommand.com> Some user with long name jr. the third esquire <user@someplace.com> Don't put quotes in the human readable names like Jack "the Jack" Jackson <jack@foo.com>" 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@foo.com> 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@newsletter.org>" 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@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (4)
-
Anton Aylward
-
Brian K. White
-
Mark Misulich
-
Rodney Baker