|
MongerMail.pm FAQ
This FAQ is to answer some common questions about using MongerMail.pm
along with some example code.
- How do I install MongerMail?
- What are the system requirements for MongerMail?
- How do I acces MongerMail from my Perl program?
- Does this use sendmail of SMTP?
- How do I find the path to sendmail?
- How do I specify who I want to send an attachment to?
- How do I specify that the e-mail is coming from me?
- Can I CC or BCC and mailing with an attachment?
- How do I specify the subject line for the email going out?
- How do I include a message in the body of the email?
- How do I attach a file?
- What types of files can I attach?
- How do I attach more than one file?
- How do I make the program send the e-mail with the attachment?
- What is the minimum code required to make this work?
- What type of encoding does MongerMail use?
Back To FAQ List
- How do I install MongerMail?
- You do not need to "install" MongerMail in the usual sense of the word. Most Perl
modules get installed on the server so they are globally accessible. To do this, however,
you usually need Root access (be the System Administrator). MongerMail was written so that
you can use it without having it "installed" on the server. All you have to do is place it
in the same directory as the script using it. For example, if you had a program called
"send_a_mail.pl", then you would put the MongerMail.pm file in the same directory. This directories
contents would now be:
MongerMail.pm
send_a_mail.pl
Top
- What are the system requirements for MongerMail?
- System requirements are simple:
- You must be on a UNIX web server.
- You must have Perl5 or higher installed.
- You must have a Perl script that accesses MongerMail.pm.
NOTE: MongerMail.pm is NOT a stand alone script that you can call in your
browser or link to. It is a Perl module. This means that it allows Perl program using
it access to certain functions/methods that the module contains.
Top
- How do I acces MongerMail from my Perl program?
- In your Perl program, you must tell it that it is going to use MongerMail.pm. This is
done by simply placing the line:
use MongerMail;
Next, you must know what the path to sendmail is on your server. The path to sendmail usually
looks like this:
/usr/sbin/sendmail
If you don't know the path to sendmail, check your virtual hosts FAQ pages or ask the System
Administrator. If either of these are unavailable, then download our utility
zip file, install the file "env_vars.pl" by placing it in your cgi-bin and CHMODing 755. Next
call it in your browser. About half way down the page you will see (on 95% of servers) a listing
of available paths to both sendmail and Perl.
Finally, create a new object. This is done easily. For this example, the path to sendmail
is "/usr/sbin/sendmail", this may be different on your server:
use MongerMail;
my $mail = new MongerMail("/usr/sbin/sendmail");
That's it. Your ready to proceed.
Top
- Does this use sendmail of SMTP?
- MongerMail uses sendmail and does NOT use SMTP. A future upgrade of MongerMail is planned that will
make use of SMTP.
Top
- How do I find the path to sendmail?
- If you don't know the path to sendmail, check your virtual hosts FAQ pages or ask the System
Administrator. If either of these are unavailable, then download our utility
zip file, install the file "env_vars.pl" by placing it in your cgi-bin and CHMODing 755. Next
call it in your browser. About half way down the page you will see (on 95% of servers) a listing
of available paths to both sendmail and Perl.
Top
- How do I specify who I want to send an attachment to?
- Having created your mail object, you must now specify the "To" value. This is done
by passing the e-mail address to the $mail object like this:
$mail->to('john@somewhere.com');
You can also pass the e-mail address as a variable:
$mail->to($send_to);
You can specify multiple recipients in the "To" field by separateing their names with a comma:
$mail->to('joe@foo.com,sue@foo.com,bill@foo.com');
or
$send_to = "joe\@foo.com,sue\@foo.com,bill\@foo.com";
$mail->to($send_to);
Top
- How do I specify that the e-mail is coming from me?
- You specify your own e-mail address in the from field exactly the same as you specify
the "To" field (above) with one minor change:
$mail->from('youremail@email.com');
or as a variable
$myemail = 'youremail@email.com';
$mail->from($myemail);
Top
- Can I CC or BCC and mailing with an attachment?
- Yes. This is done exactly like specifying the "To" recipient (including multiple recipients) except that you are
specifying the method like this:
$mail->cc('joe@foo.com,sue@foo.com,bill@foo.com');
or
$send_cc = "joe\@foo.com,sue\@foo.com,bill\@foo.com";
$mail->cc($send_to);
To BCC:
$mail->bcc('joe@foo.com,sue@foo.com,bill@foo.com');
or
$send_to = "joe\@foo.com,sue\@foo.com,bill\@foo.com";
$mail->bcc($send_to);
Note: with the "cc" and "bcc" methods, you can pass a list of email addresses, i.e.:
@copies = ("joe\@foo.com", "sue\@foo.com", "bill\@foo.com");
$mail->cc(@copies);
or
$mail->bcc(@copies);
Top
- How do I specify the subject line for the email going out?
- The subject line is simply specified with the subject method:
$mail->subject("Here is your file!");
Top
- How do I include a message in the body of the email?
- Usually, the body of an e-mail message will go in a series of print statements like this:
print MAIL "blah blah blah blah blah blah\n";
print MAIL "yadda yadda yadda yadda yadda\n";
print MAIL "blah blah blah blah blah blah\n";
print MAIL "yadda yadda yadda yadda yadda\n";
print MAIL "blah blah blah blah blah blah\n";
print MAIL "yadda yadda yadda yadda yadda\n";
Taking the above example, you can add the text in with a slight modification:
$body = "blah blah blah blah blah blah\n";
$body .= "yadda yadda yadda yadda yadda\n";
$body .= "blah blah blah blah blah blah\n";
$body .= "yadda yadda yadda yadda yadda\n";
$body .= "blah blah blah blah blah blah\n";
$body .= "yadda yadda yadda yadda yadda\n";
$mail->content($body);
You can also enter the text directly into the method call:
$mail->content("Here is the contents of the email message.");
Top
- How do I attach a file?
- Attaching a file is simplicity itself. The first thing you need is the absolute path
to the file you want to attach. An absolute path is NOT a URL. It is the full path from
the server root. For example, the full path to this faq document is:
/usr/pscom/public_html/Library/faq/MongerMail_faq.html
Once you have that, all you have to do is:
$mail->attachment("/usr/pscom/public_html/Library/faq/MongerMail_faq.html");
You can also do this as a variable:
$file = "/usr/pscom/public_html/Library/faq/MongerMail_faq.html";
$mail->attachment($file);
Top
- What types of files can I attach?
- You can attach any type of file that you want. ASCII (text) or binary (everything else).
The MongerMail module takes care of that and you do NOT need to specify anything about the
file type.
If you run across a file type that MongerMail does not seem to support, please contact us
so we can make modifications to account for it.
Top
- How do I attach more than one file?
- Just like the above examples, except you pass the attachment method a list of files:
@files = (
'/usr/pscom/public_html/Library/faq/MongerMail_faq.html',
'/usr/pscom/public_html/some/other/path/mypicute.jpg',
'/usr/pscom/public_html/applicationform.doc',
);
$mail->attachment(@files);
Top
- How do I make the program send the e-mail with the attachment?
- Once you have specified the "To", "From" and "Content", you tell the program
to send the email with it like this:
$mail->send;
Note that the minimum information you must require is $mail->to($email) and $mail->from($myemail).
You can send a blank email with this but why bother?
Top
- What is the minimum code required to make this work?
- Using MongerMail makes the whole sending of an email much simpler than having to type
out line after line of code. Here are three examples:
- Send an e-mail with no attachment:
#!/usr/bin/perl
my $email = "youremail@email.com";
my $sendto = "info@somedomain.com";
my $mailprogram = "/usr/sbin/sendmail";
use MongerMail;
my $mail = new MongerMail($mailprogram);
$mail->to($sendto);
$mail->from($email);
$mail->subject("Here is your mailing!");
my $body = "Hi!\nI\'m sending you this mailing from my own Perl program\n";
$body .= "so that I can see how the Perl module that is called\n";
$body .= "MongerMail works. Let me know when you get this message!\n\n";
$mail->content($body);
$mail->send;
print "Content-type: text/html\n\n";
print "Mailing has been send\n";
exit;
- Send an e-mail with an attachment to three people:
#!/usr/bin/perl
my $email = "youremail@email.com";
my $sendto = "youremail2@email.com";
my @copyto = ("youremail2@email.com", "youremail3@email.com");
my $file = "/usr/local/pscom/public_html/super/secret/file.doc";
my $mailprogram = "/usr/sbin/sendmail";
use MongerMail;
my $mail = new MongerMail($mailprogram);
$mail->to($sendto);
$mail->from($email);
$mail->cc(@copyto);
$mail->subject("Here is your mailing!");
$mail->attachment($file);
$mail->content("Here is the file you requested!\n\n");
$mail->send;
print "Content-type: text/html\n\n";
print "Mailing has been sent to three people with an attachment.\n";
exit;
- Send an e-mail with an attachment to two people, with two attachments:
#!/usr/bin/perl
my $email = "youremail@email.com";
my $sendto = "youremail2@email.com";
my $bcccopyto = "youremail3@email.com";
my @file = (
"/usr/local/pscom/public_html/super/secret/file.doc",
"/usr/local/pscom/public_html/super/secret/image.png",
);
my $mailprogram = "/usr/sbin/sendmail";
use MongerMail;
my $mail = new MongerMail($mailprogram);
$mail->to($sendto);
$mail->from($email);
$mail->bcc($bcccopyto);
$mail->subject("Here is your mailing!");
$mail->attachment(@file);
$mail->content("Here are the files you requested!\n\n");
$mail->send;
print "Content-type: text/html\n\n";
print "Mailing has been sent to three people with an attachment.\n";
exit;
Top
- What type of encoding does MongerMail use?
- By default, MongerMail uses Base64 encoding. You can change this to "uuencode" if you
need to like this:
$mail->encoding('uuencode');
Conversley, you can switch back to Base64 like this:
$mail->encoding('base64');
Note that the values 'uuencode' and 'base64' are the only two values this
method will permit and they ARE case-sensitive.
Top
|