# Simple E-mail List

1. Mar 5, 2010

### cepheid

Staff Emeritus
If I have a .TXT file with comma-separated e-mail addresses, is there some way that I can quickly send an e-mail out with all of them in the BCC field? For example, could this be done from the command line in Linux (Ubuntu 9.04)? Is there some way that I could have the contents of another .TXT file that is the e-mail message be automatically sent to everyone on the list in this manner?

My user account on my department computer is capable of sending outgoing mail through the department's mail server, so I don't think that should be a problem.

2. Mar 5, 2010

### DaveC426913

Obviously you didn't simply copy the comma-delimited list to the clipboard and paste it into the Bcc field in your mail client, or you would have done so. So what's the catch?

3. Mar 5, 2010

### cepheid

Staff Emeritus
I was wondering if there was a faster way of doing it straight from the command line.

In the past I have done what you suggested, but it is complicated by the fact that I don't use a mail client on my desktop Linux machine in the department. The only computer I have on which I use a mail client is my Mac (a laptop). I default to webmail (Gmail) on my Linux machine. To elaborate: everything forwards to Gmail, which I can either access directly with a browser, or which I can read from my mail client on my Mac. Furthermore, the situation is complicated by the fact that a third computer is involved. The e-mail contact .TXT file in question is not maintained on either of the machines I just mentioned. It is located under a different user account on the department server. So, the steps involved are usually:

1. Use a terminal to access the department server and get a local copy of the list on one of the two computers I use (desktop Linux machine or laptop Mac).

2. Open up this local copy of the list, select all nearly 400 e-mail addresses, and paste into BCC field in either web broswer accessing Gmail or Mail client program on Mac.

3. Compose message and hit send.

If there was a way to send an e-mail out to the list directly from the command line, then I wouldn't have to worry about creating a local copy of that list. Also, it would be awesome if the message sent could also be the contents of (another) .TXT file. Then I wouldn't have to worry about using some sort of mail program in which the message had to be composed.

4. Mar 5, 2010

### Staff: Mentor

There's no way to set up some sort of e-mail client so that you can set up user groups? That would be so simple.

5. Mar 5, 2010

### rootX

I don't have the code with me but you can send email in linux (perl). I remember making a script that would send an email out for system administration purposes.

http://www.tneoh.zoneit.com/perl/SendMail/

Last edited by a moderator: Apr 24, 2017
6. Mar 5, 2010

### Staff: Mentor

Does your Linux box have sendmail on it? If so, prepare a file that contains the necessary mail headers (including Bcc:), followed by an empty line and then the message body. Let's call it message.txt. Then do something like this:

% sendmail [options] < message.txt

You'll have to find out which options you need to specify. I think you can tell it to connect to a remote mail server instead of using the local machine as the mail server. It's been years since I did this (actually it was inside a Perl script) so I don't remember the details.

A common "sendmail replacement" is Postfix, which I think is usually installed so that you can invoke it under the name 'sendmail' with the same options. Mac OS X comes with Postfix installed, or at least it once did.

[added] Or, as rootX noted, if you know Perl, you can whip up a script that uses a Perl module to send mail. I've used the Net::SMTP module which I think comes with any standard Perl installation. Here's a subroutine that I once wrote for this:

Code (Text):

#--------------------------------------------------------------------------
#  Sends an e-mail using the Net::SMTP module.
#
#    $From = address which will appear in the "From:" line. #$To = address to send the message to
#    $MessageRef = reference to an array that contains the complete # message, both header and body. # # Example: # SendMail ("me\@podunk.edu", "you\@somewhere.com", # \@MessageArray); # # The global variable$MailServer must contain the domain name
#  of the mail server to be used (e.g. mail.podunk.edu).
#
#  Make sure you have the statement 'use Net::SMTP;' at the beginning of
#
#  If one of the SMTP calls returns an error code, the message is printed
#  to standard output, along with the message itself.
#
#  To get the above output always, set $DEBUG = 1 below; set it to 0 to # turn this off. #-------------------------------------------------------------------------- sub SendMail { my ($From, $To,$MessageRef) = @_;
my $DEBUG = 0; my$MailConnection = Net::SMTP->new($MailServer) or die "Can't connect to mail server$MailServer!!\n";

$MailConnection->mail($From)
or die "Can't start message from $From\n"; if ($MailConnection->to($To)) {$MailConnection->data();
$MailConnection->datasend (@$MessageRef);
$MailConnection->dataend(); } else { print "Can't start message to$To!\n";
}
if ($MailConnection->ok()) {$DEBUG && print "\nResult from mail server:\n";
$DEBUG && print$MailConnection->code();
$DEBUG && print " ";$DEBUG && print $MailConnection->message();$DEBUG && print "\n";
$DEBUG && print "---------- message -----------\n";$DEBUG && print @$MessageRef; } else { print "\nMail failed! Response from mail server:\n"; print$MailConnection->code();
print " ";
print $MailConnection->message(); print "\n"; print "---------- attempted message -----------\n"; print @$MessageRef;
}

\$MailConnection->quit();
}

Last edited: Mar 5, 2010
7. Mar 5, 2010

### cepheid

Staff Emeritus
Wow, thanks for all the info guys! I will look through it and see if I can figure something out. I have general programming experience, but have never done any Perl scripting. That having been said, if I just figure out how to use sendmail, then I can manually run it from the command line with the requisite options each time, correct?

By the way, I typed man sendmail at the command prompt while SSH'd into my department's server (where the contact list is kept), and there was a man entry for it. So I guess that means I'm good to go, right?

EDIT: Evidently not. I get an error message saying "command not found" when I try to actually use it.

8. Mar 5, 2010

### cepheid

Staff Emeritus
WHOAH! Actually, it works fine! Googling just revealed that this application is located at /usr/sbin/sendmail, and that I just had to use the full path in the command. Also, the option you need in order for it to look for headers in the message text files is -t.

9. Mar 5, 2010

### rootX

I don't know much about perl but I think you need to point to the place where Net:SMTP/sendmail module is located. Personally, I just download sendmail file to the same folder and compiled without errors.

[Edit: 1 minute delayed]