Found in /usr/share/perl/5.34/pod/perlfaq2.pod What mailing lists are there for Perl? A comprehensive list of Perl-related mailing lists can be found at <http://lists.perl.org/> Found in /usr/share/perl/5.34/pod/perlfaq9.pod How do I parse a mail header? Use the Email::MIME module. It's well-tested and supports all the craziness that you'll see in the real world (comment-folding whitespace, encodings, comments, etc.). use Email::MIME; my $message = Email::MIME->new($rfc2822); my $subject = $message->header('Subject'); my $from = $message->header('From'); If you've already got some other kind of email object, consider passing it to Email::Abstract and then using its cast method to get an Email::MIME object: my $abstract = Email::Abstract->new($mail_message_object); my $email_mime_object = $abstract->cast('Email::MIME'); How do I check a valid mail address? (partly contributed by Aaron Sherman) This isn't as simple a question as it sounds. There are two parts: a) How do I verify that an email address is correctly formatted? b) How do I verify that an email address targets a valid recipient? Without sending mail to the address and seeing whether there's a human on the other end to answer you, you cannot fully answer part *b*, but the Email::Valid module will do both part *a* and part *b* as far as you can in real-time. Our best advice for verifying a person's mail address is to have them enter their address twice, just as you normally do to change a password. This usually weeds out typos. If both versions match, send mail to that address with a personal message. If you get the message back and they've followed your directions, you can be reasonably assured that it's real. A related strategy that's less open to forgery is to give them a PIN (personal ID number). Record the address and PIN (best that it be a random one) for later processing. In the mail you send, include a link to your site with the PIN included. If the mail bounces, you know it's not valid. If they don't click on the link, either they forged the address or (assuming they got the message) following through wasn't important so you don't need to worry about it. How do I find the user's mail address? Ask them for it. There are so many email providers available that it's unlikely the local system has any idea how to determine a user's email address. The exception is for organization-specific email (e.g. foo AT yourcompany.com) where policy can be codified in your program. In that case, you could look at $ENV{USER}, $ENV{LOGNAME}, and getpwuid($<) in scalar context, like so: my $user_name = getpwuid($<) But you still cannot make assumptions about whether this is correct, unless your policy says it is. You really are best off asking the user. How do I send email? Use the Email::Stuffer module, like so: # first, create your message my $message = Email::Stuffer->from('you AT example.com') ->to('friend AT example.com') ->subject('Happy birthday!') ->text_body("Happy birthday to you!\n"); $message->send_or_die; By default, Email::Sender::Simple (the "send" and "send_or_die" methods use this under the hood) will try "sendmail" first, if it exists in your $PATH. This generally isn't the case. If there's a remote mail server you use to send mail, consider investigating one of the Transport classes. At time of writing, the available transports include: Email::Sender::Transport::Sendmail This is the default. If you can use the mail(1) or mailx(1) program to send mail from the machine where your code runs, you should be able to use this. Email::Sender::Transport::SMTP This transport contacts a remote SMTP server over TCP. It optionally uses TLS or SSL and can authenticate to the server via SASL. Telling Email::Stuffer to use your transport is straightforward. $message->transport($email_sender_transport_object)->send_or_die; How do I use MIME to make an attachment to a mail message? Email::MIME directly supports multipart messages. Email::MIME objects themselves are parts and can be attached to other Email::MIME objects. Consult the Email::MIME documentation for more information, including all of the supported methods and examples of their use. Email::Stuffer uses Email::MIME under the hood to construct messages, and wraps the most common attachment tasks with the simple "attach" and "attach_file" methods. Email::Stuffer->to('friend AT example.com') ->subject('The file') ->attach_file('stuff.csv') ->send_or_die; How do I read email? Use the Email::Folder module, like so: use Email::Folder; my $folder = Email::Folder->new('/path/to/email/folder'); while(my $message = $folder->next_message) { # next_message returns Email::Simple objects, but we want # Email::MIME objects as they're more robust my $mime = Email::MIME->new($message->as_string); } There are different classes in the Email::Folder namespace for supporting various mailbox types. Note that these modules are generally rather limited and only support reading rather than writing.
Generated by phpman v3.7.12 Author: Che Dong Under GNU General Public License
2026-06-14 05:36 @216.73.216.200
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)