SlideShare a Scribd company logo
Sending Email with Perl
Why does it hurt so much, daddy?

2011-10-09
About Me



✤   apeiron (IRC/CPAN)

    ✤   Chris Nehren if you insist on a meatspace name

✤   I like Perl and tabletop RPGs
Tools of the trade
Tools of the trade

✤   Mail::Box (though if you don’t mind complexity, it’s really solid)
Tools of the trade

✤   Mail::Box (though if you don’t mind complexity, it’s really solid)

✤   Email::Send
Tools of the trade

✤   Mail::Box (though if you don’t mind complexity, it’s really solid)

✤   Email::Send

✤   Email::Valid
Tools of the trade

✤   Mail::Box (though if you don’t mind complexity, it’s really solid)

✤   Email::Send

✤   Email::Valid

✤   Email::Address
Tools of the trade

✤   Mail::Box (though if you don’t mind complexity, it’s really solid)

✤   Email::Send

✤   Email::Valid

✤   Email::Address

✤   Email::MIME
Tools of the trade

✤   Mail::Box (though if you don’t mind complexity, it’s really solid)

✤   Email::Send

✤   Email::Valid

✤   Email::Address

✤   Email::MIME

✤   Email::Sender
Email::Valid
Email::Valid

✤   Simple email address validation
Email::Valid

✤   Simple email address validation

✤   One (class) method: address($address)
Email::Valid

✤   Simple email address validation

✤   One (class) method: address($address)

✤   Call method
Email::Valid

✤   Simple email address validation

✤   One (class) method: address($address)

✤   Call method

✤   Receive Bacon*




Bacon may or may not be imaginary. Consult your Perl vendor for details.
Email::Valid

✤   Simple email address validation

✤   One (class) method: address($address)

✤   Call method

✤   Receive Bacon*

✤   Also receive true/false value depending upon whether it’s valid




Bacon may or may not be imaginary. Consult your Perl vendor for details.
Email::Valid

✤   Simple email address validation

✤   One (class) method: address($address)

✤   Call method

✤   Receive Bacon*

✤   Also receive true/false value depending upon whether it’s valid

✤   There are actually lots of methods for inspecting the address, but
    address is the one you’re likely to use the most.
Bacon may or may not be imaginary. Consult your Perl vendor for details.
Usage Example
#!env perl
use 5.014;
use strictures 1;
use Email::Valid;

say Email::Valid->address('foo') ? "valid" : "not";
say Email::Valid->address('foo@bar.com') ? "valid" : "not";
say Email::Valid->address('foo+baz@bar.com') ? "valid" : "not";

# yields this:
not
valid
valid
Email::Address
Email::Address


✤   Used for accessing different parts of an address
Email::Address


✤   Used for accessing different parts of an address

✤   Some mutators, but primarily accessors
Email::Address


✤   Used for accessing different parts of an address

✤   Some mutators, but primarily accessors

✤   Two constructors: parse and new
Email::Address


✤   Used for accessing different parts of an address

✤   Some mutators, but primarily accessors

✤   Two constructors: parse and new

    ✤   parse returns a list of addresses
Email::Address


   ✤   Used for accessing different parts of an address

   ✤   Some mutators, but primarily accessors

   ✤   Two constructors: parse and new

        ✤   parse returns a list of addresses

        ✤   new accepts a phrase, address, and comment*


Actually it accepts a fourth argument, an original string. But you probably should ignore it.
Email::Address Methods
Email::Address Methods

✤   address

    ✤   get/set actual address, e.g. foo@bar.com
Email::Address Methods

✤   address

    ✤   get/set actual address, e.g. foo@bar.com

✤   host

    ✤   get/set the hostname of the address, e.g. bar.com
Email::Address Methods

✤   address

    ✤   get/set actual address, e.g. foo@bar.com

✤   host

    ✤   get/set the hostname of the address, e.g. bar.com

✤   user

    ✤   get/set the local part of the address, e.g. foo
Usage example
#!env perl
use 5.014;
use strictures 1;
use Email::Address;

my ($one, $two, $three) = Email::Address->parse(
  'foo@bar.com, baz@quux.com, "hello" <me@example.com>'
);
say $three; # stringify overload
say $three->address; # raw address, no phrase/comment.
say $three->host;
say $three->user;

# yields:
"hello" <me@example.com>
example.com
me
me@example.com
Email::MIME -- Why?
Email::MIME -- Why?


✤   It’s simple
Email::MIME -- Why?


✤   It’s simple

✤   It’s easy
Email::MIME -- Why?


✤   It’s simple

✤   It’s easy

✤   It works
Email::MIME -- Why?


✤   It’s simple

✤   It’s easy

✤   It works

✤   ... but really it just sucks the least.
So how do you
use it?
This won’t hurt a bit.
Methods of Email::MIME
Methods of Email::MIME

✤   body_str_set($unicode)
    ✤   sets body to given Unicode characters. Warning: clears other parts!
Methods of Email::MIME

✤   body_str_set($unicode)
    ✤   sets body to given Unicode characters. Warning: clears other parts!
✤   header_str_set($header, $unicode)
    ✤   like body_str_set, but for headers.
Methods of Email::MIME

✤   body_str_set($unicode)
    ✤   sets body to given Unicode characters. Warning: clears other parts!
✤   header_str_set($header, $unicode)
    ✤   like body_str_set, but for headers.
✤   parts_set(@email_mime_objects)
    ✤   replaces the parts of the object with the given parts
Methods of Email::MIME

✤   body_str_set($unicode)
    ✤   sets body to given Unicode characters. Warning: clears other parts!
✤   header_str_set($header, $unicode)
    ✤   like body_str_set, but for headers.
✤   parts_set(@email_mime_objects)
    ✤   replaces the parts of the object with the given parts
✤   parts_add(@more_parts)
    ✤   appends, not sets
Methods of Email::MIME

✤   body_str_set($unicode)
    ✤   sets body to given Unicode characters. Warning: clears other parts!
✤   header_str_set($header, $unicode)
    ✤   like body_str_set, but for headers.
✤   parts_set(@email_mime_objects)
    ✤   replaces the parts of the object with the given parts
✤   parts_add(@more_parts)
    ✤   appends, not sets
✤   walk_parts($coderef)
    ✤   give it a callback, gets called with Email::MIME objects
From the new perlfaq9:
#!env perl
use strictures 1;
use Email::MIME;

my $message = Email::MIME->create(
   header_str => [
      From    => 'you@example.com',
      To      => 'friend@example.com',
      Subject => 'Happy birthday!',
   ],
   body => 'Happy birthday to you!',
);
If we call
        $message->as_string,

From: you@example.com
To: friend@example.com
Subject: Happy birthday!
Date: Sat, 8 Oct 2011 16:56:41 -0400
MIME-Version: 1.0

Happy birthday to you!
Email::Sender
Email::Sender


✤   Moose-based interface to different ways of sending email messages
Email::Sender


✤   Moose-based interface to different ways of sending email messages

✤   Different transports for different purposes
Email::Sender


✤   Moose-based interface to different ways of sending email messages

✤   Different transports for different purposes

✤   Suggested interface (for now) is Email::Sender::Simple
Email::Sender


✤   Moose-based interface to different ways of sending email messages

✤   Different transports for different purposes

✤   Suggested interface (for now) is Email::Sender::Simple

    ✤   This exposes one function: sendmail().
Email::Sender


✤   Moose-based interface to different ways of sending email messages

✤   Different transports for different purposes

✤   Suggested interface (for now) is Email::Sender::Simple

    ✤   This exposes one function: sendmail().

✤   sendmail() accepts Email::MIME objects, so we’re in business.
Email::Sender Transport Gazetteer
Email::Sender Transport Gazetteer
✤   Email::Sender::Transport::Sendmail

    ✤   tries to use /usr/sbin/sendmail or the like; you probably need to
        smarthost / relay
Email::Sender Transport Gazetteer
✤   Email::Sender::Transport::Sendmail

    ✤   tries to use /usr/sbin/sendmail or the like; you probably need to
        smarthost / relay
✤   Email::Sender::Transport::SMTP

    ✤   Send mail through an SMTP server, optionally with SASL
        authentication.
Email::Sender Transport Gazetteer
✤   Email::Sender::Transport::Sendmail

    ✤   tries to use /usr/sbin/sendmail or the like; you probably need to
        smarthost / relay
✤   Email::Sender::Transport::SMTP

    ✤   Send mail through an SMTP server, optionally with SASL
        authentication.
✤   Email::Sender::Transport::SMTP::TLS

    ✤   Like the above, but uses TLS. If you use Gmail, you’ll need this.
Email::Sender Transport Gazetteer
✤   Email::Sender::Transport::Sendmail

    ✤   tries to use /usr/sbin/sendmail or the like; you probably need to
        smarthost / relay
✤   Email::Sender::Transport::SMTP

    ✤   Send mail through an SMTP server, optionally with SASL
        authentication.
✤   Email::Sender::Transport::SMTP::TLS

    ✤   Like the above, but uses TLS. If you use Gmail, you’ll need this.
✤   Email::Sender::Transport::Test

    ✤   Delivers to an in-memory structure for analysis
Example Usages
sendmail($message); # default transport
sendmail(
  $message,
  {
    transport => Email::Sender::Transport::SMTP->new(
       host => ‘mx.example.com’,
       port => 25,
    );
  }
);
Bonus material: pmail(1) demo
When You Run Out Of Material, Demo A Very Flexible Program You Wrote

More Related Content

Similar to Sending email with perl

Ruby
RubyRuby
i &lt;3 email
i &lt;3 emaili &lt;3 email
i &lt;3 email
Ricardo Signes
 
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrapNode mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
Katy Slemon
 
Eventful Email in Ruby
Eventful Email in RubyEventful Email in Ruby
Eventful Email in Ruby
hassox
 
N E T Coding Best Practices
N E T  Coding  Best  PracticesN E T  Coding  Best  Practices
N E T Coding Best Practices
Abhishek Desai
 
EmailTracing.ppt
EmailTracing.pptEmailTracing.ppt
EmailTracing.ppt
govindanonymous143
 
Send email
Send emailSend email
Send email
Joselito Catanes
 
How To Build A Bulk Email Sending Application In PHP
How To Build A Bulk Email Sending Application In PHPHow To Build A Bulk Email Sending Application In PHP
How To Build A Bulk Email Sending Application In PHP
Sudheer Satyanarayana
 
Классифицируем текст в iOS без CoreML: как и зачем?
Классифицируем текст в iOS без CoreML: как и зачем? Классифицируем текст в iOS без CoreML: как и зачем?
Классифицируем текст в iOS без CoreML: как и зачем?
EatDog
 
Action Mailer
Action MailerAction Mailer
Action Mailer
SHC
 
Validate Email with JavaScript.pdf
Validate Email with JavaScript.pdfValidate Email with JavaScript.pdf
Validate Email with JavaScript.pdf
EmailConcern
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
Dave Cross
 
Email Configuration
Email ConfigurationEmail Configuration
Email Configuration
ProdigyView
 
Setting up your own email server with hmailserver
Setting up your own email server with hmailserverSetting up your own email server with hmailserver
Setting up your own email server with hmailserver
rifqirr
 
Python session.11 By Shanmugam
Python session.11 By ShanmugamPython session.11 By Shanmugam
Python session.11 By Shanmugam
Navaneethan Naveen
 
Python session 11
Python session 11Python session 11
Python session 11
Navaneethan Naveen
 
Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP
yucefmerhi
 
XML::Writer::Simple
XML::Writer::SimpleXML::Writer::Simple
XML::Writer::Simple
Alberto Simões
 
Perl Teach-In (part 1)
Perl Teach-In (part 1)Perl Teach-In (part 1)
Perl Teach-In (part 1)
Dave Cross
 
Hide email address in sourc...
Hide email address in sourc...Hide email address in sourc...
Hide email address in sourc...
chaitanya535
 

Similar to Sending email with perl (20)

Ruby
RubyRuby
Ruby
 
i &lt;3 email
i &lt;3 emaili &lt;3 email
i &lt;3 email
 
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrapNode mailer example how to send email using nodemailer with gmail &amp; mailtrap
Node mailer example how to send email using nodemailer with gmail &amp; mailtrap
 
Eventful Email in Ruby
Eventful Email in RubyEventful Email in Ruby
Eventful Email in Ruby
 
N E T Coding Best Practices
N E T  Coding  Best  PracticesN E T  Coding  Best  Practices
N E T Coding Best Practices
 
EmailTracing.ppt
EmailTracing.pptEmailTracing.ppt
EmailTracing.ppt
 
Send email
Send emailSend email
Send email
 
How To Build A Bulk Email Sending Application In PHP
How To Build A Bulk Email Sending Application In PHPHow To Build A Bulk Email Sending Application In PHP
How To Build A Bulk Email Sending Application In PHP
 
Классифицируем текст в iOS без CoreML: как и зачем?
Классифицируем текст в iOS без CoreML: как и зачем? Классифицируем текст в iOS без CoreML: как и зачем?
Классифицируем текст в iOS без CoreML: как и зачем?
 
Action Mailer
Action MailerAction Mailer
Action Mailer
 
Validate Email with JavaScript.pdf
Validate Email with JavaScript.pdfValidate Email with JavaScript.pdf
Validate Email with JavaScript.pdf
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Email Configuration
Email ConfigurationEmail Configuration
Email Configuration
 
Setting up your own email server with hmailserver
Setting up your own email server with hmailserverSetting up your own email server with hmailserver
Setting up your own email server with hmailserver
 
Python session.11 By Shanmugam
Python session.11 By ShanmugamPython session.11 By Shanmugam
Python session.11 By Shanmugam
 
Python session 11
Python session 11Python session 11
Python session 11
 
Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP
 
XML::Writer::Simple
XML::Writer::SimpleXML::Writer::Simple
XML::Writer::Simple
 
Perl Teach-In (part 1)
Perl Teach-In (part 1)Perl Teach-In (part 1)
Perl Teach-In (part 1)
 
Hide email address in sourc...
Hide email address in sourc...Hide email address in sourc...
Hide email address in sourc...
 

Recently uploaded

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 

Recently uploaded (20)

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 

Sending email with perl

  • 1. Sending Email with Perl Why does it hurt so much, daddy? 2011-10-09
  • 2. About Me ✤ apeiron (IRC/CPAN) ✤ Chris Nehren if you insist on a meatspace name ✤ I like Perl and tabletop RPGs
  • 3. Tools of the trade
  • 4. Tools of the trade ✤ Mail::Box (though if you don’t mind complexity, it’s really solid)
  • 5. Tools of the trade ✤ Mail::Box (though if you don’t mind complexity, it’s really solid) ✤ Email::Send
  • 6. Tools of the trade ✤ Mail::Box (though if you don’t mind complexity, it’s really solid) ✤ Email::Send ✤ Email::Valid
  • 7. Tools of the trade ✤ Mail::Box (though if you don’t mind complexity, it’s really solid) ✤ Email::Send ✤ Email::Valid ✤ Email::Address
  • 8. Tools of the trade ✤ Mail::Box (though if you don’t mind complexity, it’s really solid) ✤ Email::Send ✤ Email::Valid ✤ Email::Address ✤ Email::MIME
  • 9. Tools of the trade ✤ Mail::Box (though if you don’t mind complexity, it’s really solid) ✤ Email::Send ✤ Email::Valid ✤ Email::Address ✤ Email::MIME ✤ Email::Sender
  • 11. Email::Valid ✤ Simple email address validation
  • 12. Email::Valid ✤ Simple email address validation ✤ One (class) method: address($address)
  • 13. Email::Valid ✤ Simple email address validation ✤ One (class) method: address($address) ✤ Call method
  • 14. Email::Valid ✤ Simple email address validation ✤ One (class) method: address($address) ✤ Call method ✤ Receive Bacon* Bacon may or may not be imaginary. Consult your Perl vendor for details.
  • 15. Email::Valid ✤ Simple email address validation ✤ One (class) method: address($address) ✤ Call method ✤ Receive Bacon* ✤ Also receive true/false value depending upon whether it’s valid Bacon may or may not be imaginary. Consult your Perl vendor for details.
  • 16. Email::Valid ✤ Simple email address validation ✤ One (class) method: address($address) ✤ Call method ✤ Receive Bacon* ✤ Also receive true/false value depending upon whether it’s valid ✤ There are actually lots of methods for inspecting the address, but address is the one you’re likely to use the most. Bacon may or may not be imaginary. Consult your Perl vendor for details.
  • 17. Usage Example #!env perl use 5.014; use strictures 1; use Email::Valid; say Email::Valid->address('foo') ? "valid" : "not"; say Email::Valid->address('foo@bar.com') ? "valid" : "not"; say Email::Valid->address('foo+baz@bar.com') ? "valid" : "not"; # yields this: not valid valid
  • 19. Email::Address ✤ Used for accessing different parts of an address
  • 20. Email::Address ✤ Used for accessing different parts of an address ✤ Some mutators, but primarily accessors
  • 21. Email::Address ✤ Used for accessing different parts of an address ✤ Some mutators, but primarily accessors ✤ Two constructors: parse and new
  • 22. Email::Address ✤ Used for accessing different parts of an address ✤ Some mutators, but primarily accessors ✤ Two constructors: parse and new ✤ parse returns a list of addresses
  • 23. Email::Address ✤ Used for accessing different parts of an address ✤ Some mutators, but primarily accessors ✤ Two constructors: parse and new ✤ parse returns a list of addresses ✤ new accepts a phrase, address, and comment* Actually it accepts a fourth argument, an original string. But you probably should ignore it.
  • 25. Email::Address Methods ✤ address ✤ get/set actual address, e.g. foo@bar.com
  • 26. Email::Address Methods ✤ address ✤ get/set actual address, e.g. foo@bar.com ✤ host ✤ get/set the hostname of the address, e.g. bar.com
  • 27. Email::Address Methods ✤ address ✤ get/set actual address, e.g. foo@bar.com ✤ host ✤ get/set the hostname of the address, e.g. bar.com ✤ user ✤ get/set the local part of the address, e.g. foo
  • 28. Usage example #!env perl use 5.014; use strictures 1; use Email::Address; my ($one, $two, $three) = Email::Address->parse( 'foo@bar.com, baz@quux.com, "hello" <me@example.com>' ); say $three; # stringify overload say $three->address; # raw address, no phrase/comment. say $three->host; say $three->user; # yields: "hello" <me@example.com> example.com me me@example.com
  • 30. Email::MIME -- Why? ✤ It’s simple
  • 31. Email::MIME -- Why? ✤ It’s simple ✤ It’s easy
  • 32. Email::MIME -- Why? ✤ It’s simple ✤ It’s easy ✤ It works
  • 33. Email::MIME -- Why? ✤ It’s simple ✤ It’s easy ✤ It works ✤ ... but really it just sucks the least.
  • 34. So how do you use it? This won’t hurt a bit.
  • 36. Methods of Email::MIME ✤ body_str_set($unicode) ✤ sets body to given Unicode characters. Warning: clears other parts!
  • 37. Methods of Email::MIME ✤ body_str_set($unicode) ✤ sets body to given Unicode characters. Warning: clears other parts! ✤ header_str_set($header, $unicode) ✤ like body_str_set, but for headers.
  • 38. Methods of Email::MIME ✤ body_str_set($unicode) ✤ sets body to given Unicode characters. Warning: clears other parts! ✤ header_str_set($header, $unicode) ✤ like body_str_set, but for headers. ✤ parts_set(@email_mime_objects) ✤ replaces the parts of the object with the given parts
  • 39. Methods of Email::MIME ✤ body_str_set($unicode) ✤ sets body to given Unicode characters. Warning: clears other parts! ✤ header_str_set($header, $unicode) ✤ like body_str_set, but for headers. ✤ parts_set(@email_mime_objects) ✤ replaces the parts of the object with the given parts ✤ parts_add(@more_parts) ✤ appends, not sets
  • 40. Methods of Email::MIME ✤ body_str_set($unicode) ✤ sets body to given Unicode characters. Warning: clears other parts! ✤ header_str_set($header, $unicode) ✤ like body_str_set, but for headers. ✤ parts_set(@email_mime_objects) ✤ replaces the parts of the object with the given parts ✤ parts_add(@more_parts) ✤ appends, not sets ✤ walk_parts($coderef) ✤ give it a callback, gets called with Email::MIME objects
  • 41. From the new perlfaq9: #!env perl use strictures 1; use Email::MIME; my $message = Email::MIME->create( header_str => [ From => 'you@example.com', To => 'friend@example.com', Subject => 'Happy birthday!', ], body => 'Happy birthday to you!', );
  • 42. If we call $message->as_string, From: you@example.com To: friend@example.com Subject: Happy birthday! Date: Sat, 8 Oct 2011 16:56:41 -0400 MIME-Version: 1.0 Happy birthday to you!
  • 44. Email::Sender ✤ Moose-based interface to different ways of sending email messages
  • 45. Email::Sender ✤ Moose-based interface to different ways of sending email messages ✤ Different transports for different purposes
  • 46. Email::Sender ✤ Moose-based interface to different ways of sending email messages ✤ Different transports for different purposes ✤ Suggested interface (for now) is Email::Sender::Simple
  • 47. Email::Sender ✤ Moose-based interface to different ways of sending email messages ✤ Different transports for different purposes ✤ Suggested interface (for now) is Email::Sender::Simple ✤ This exposes one function: sendmail().
  • 48. Email::Sender ✤ Moose-based interface to different ways of sending email messages ✤ Different transports for different purposes ✤ Suggested interface (for now) is Email::Sender::Simple ✤ This exposes one function: sendmail(). ✤ sendmail() accepts Email::MIME objects, so we’re in business.
  • 50. Email::Sender Transport Gazetteer ✤ Email::Sender::Transport::Sendmail ✤ tries to use /usr/sbin/sendmail or the like; you probably need to smarthost / relay
  • 51. Email::Sender Transport Gazetteer ✤ Email::Sender::Transport::Sendmail ✤ tries to use /usr/sbin/sendmail or the like; you probably need to smarthost / relay ✤ Email::Sender::Transport::SMTP ✤ Send mail through an SMTP server, optionally with SASL authentication.
  • 52. Email::Sender Transport Gazetteer ✤ Email::Sender::Transport::Sendmail ✤ tries to use /usr/sbin/sendmail or the like; you probably need to smarthost / relay ✤ Email::Sender::Transport::SMTP ✤ Send mail through an SMTP server, optionally with SASL authentication. ✤ Email::Sender::Transport::SMTP::TLS ✤ Like the above, but uses TLS. If you use Gmail, you’ll need this.
  • 53. Email::Sender Transport Gazetteer ✤ Email::Sender::Transport::Sendmail ✤ tries to use /usr/sbin/sendmail or the like; you probably need to smarthost / relay ✤ Email::Sender::Transport::SMTP ✤ Send mail through an SMTP server, optionally with SASL authentication. ✤ Email::Sender::Transport::SMTP::TLS ✤ Like the above, but uses TLS. If you use Gmail, you’ll need this. ✤ Email::Sender::Transport::Test ✤ Delivers to an in-memory structure for analysis
  • 54. Example Usages sendmail($message); # default transport sendmail( $message, { transport => Email::Sender::Transport::SMTP->new( host => ‘mx.example.com’, port => 25, ); } );
  • 55. Bonus material: pmail(1) demo When You Run Out Of Material, Demo A Very Flexible Program You Wrote

Editor's Notes

  1. \n
  2. \n
  3. There are a lot of email modules on CPAN. A lot. No, really. I could fill 20 minutes just listing them all. This talk only has time to focus on the most recommended modules.\n\nThere&amp;#x2019;s a number of things you need to do to make sure you&amp;#x2019;re sending email correctly, including address validation, message construction, and actually sending the message. The tools to do this have evolved over the years. Some have fallen out of favor because other tools do 80% of the work in 20% of the code. Others are just deprecated because of problems in architecture or implementation. This talk will be covering the current recommended state of the art \n\nYes, they use Moose. Deal with it.\n
  4. There are a lot of email modules on CPAN. A lot. No, really. I could fill 20 minutes just listing them all. This talk only has time to focus on the most recommended modules.\n\nThere&amp;#x2019;s a number of things you need to do to make sure you&amp;#x2019;re sending email correctly, including address validation, message construction, and actually sending the message. The tools to do this have evolved over the years. Some have fallen out of favor because other tools do 80% of the work in 20% of the code. Others are just deprecated because of problems in architecture or implementation. This talk will be covering the current recommended state of the art \n\nYes, they use Moose. Deal with it.\n
  5. There are a lot of email modules on CPAN. A lot. No, really. I could fill 20 minutes just listing them all. This talk only has time to focus on the most recommended modules.\n\nThere&amp;#x2019;s a number of things you need to do to make sure you&amp;#x2019;re sending email correctly, including address validation, message construction, and actually sending the message. The tools to do this have evolved over the years. Some have fallen out of favor because other tools do 80% of the work in 20% of the code. Others are just deprecated because of problems in architecture or implementation. This talk will be covering the current recommended state of the art \n\nYes, they use Moose. Deal with it.\n
  6. There are a lot of email modules on CPAN. A lot. No, really. I could fill 20 minutes just listing them all. This talk only has time to focus on the most recommended modules.\n\nThere&amp;#x2019;s a number of things you need to do to make sure you&amp;#x2019;re sending email correctly, including address validation, message construction, and actually sending the message. The tools to do this have evolved over the years. Some have fallen out of favor because other tools do 80% of the work in 20% of the code. Others are just deprecated because of problems in architecture or implementation. This talk will be covering the current recommended state of the art \n\nYes, they use Moose. Deal with it.\n
  7. There are a lot of email modules on CPAN. A lot. No, really. I could fill 20 minutes just listing them all. This talk only has time to focus on the most recommended modules.\n\nThere&amp;#x2019;s a number of things you need to do to make sure you&amp;#x2019;re sending email correctly, including address validation, message construction, and actually sending the message. The tools to do this have evolved over the years. Some have fallen out of favor because other tools do 80% of the work in 20% of the code. Others are just deprecated because of problems in architecture or implementation. This talk will be covering the current recommended state of the art \n\nYes, they use Moose. Deal with it.\n
  8. There are a lot of email modules on CPAN. A lot. No, really. I could fill 20 minutes just listing them all. This talk only has time to focus on the most recommended modules.\n\nThere&amp;#x2019;s a number of things you need to do to make sure you&amp;#x2019;re sending email correctly, including address validation, message construction, and actually sending the message. The tools to do this have evolved over the years. Some have fallen out of favor because other tools do 80% of the work in 20% of the code. Others are just deprecated because of problems in architecture or implementation. This talk will be covering the current recommended state of the art \n\nYes, they use Moose. Deal with it.\n
  9. Probably want to make sure our email addresses are valid before trying to send something to one, or even construct an email containing one. So we have Email::Valid for that. It&amp;#x2019;s simple and it does one thing. It&amp;#x2019;s got one class method and that&amp;#x2019;s all it needs.\n
  10. Probably want to make sure our email addresses are valid before trying to send something to one, or even construct an email containing one. So we have Email::Valid for that. It&amp;#x2019;s simple and it does one thing. It&amp;#x2019;s got one class method and that&amp;#x2019;s all it needs.\n
  11. Probably want to make sure our email addresses are valid before trying to send something to one, or even construct an email containing one. So we have Email::Valid for that. It&amp;#x2019;s simple and it does one thing. It&amp;#x2019;s got one class method and that&amp;#x2019;s all it needs.\n
  12. Probably want to make sure our email addresses are valid before trying to send something to one, or even construct an email containing one. So we have Email::Valid for that. It&amp;#x2019;s simple and it does one thing. It&amp;#x2019;s got one class method and that&amp;#x2019;s all it needs.\n
  13. Probably want to make sure our email addresses are valid before trying to send something to one, or even construct an email containing one. So we have Email::Valid for that. It&amp;#x2019;s simple and it does one thing. It&amp;#x2019;s got one class method and that&amp;#x2019;s all it needs.\n
  14. Probably want to make sure our email addresses are valid before trying to send something to one, or even construct an email containing one. So we have Email::Valid for that. It&amp;#x2019;s simple and it does one thing. It&amp;#x2019;s got one class method and that&amp;#x2019;s all it needs.\n
  15. Probably want to make sure our email addresses are valid before trying to send something to one, or even construct an email containing one. So we have Email::Valid for that. It&amp;#x2019;s simple and it does one thing. It&amp;#x2019;s got one class method and that&amp;#x2019;s all it needs.\n
  16. \n
  17. If we want to do something with our addresses before sending them, e.g. to enforce some sort of policy or business logic, Email::Address gives us tools to inspect and reason about our addresses. It provides methods for looking at all the different parts of an email address, including things you likely won&amp;#x2019;t care about like the phrase or the comment.\n
  18. If we want to do something with our addresses before sending them, e.g. to enforce some sort of policy or business logic, Email::Address gives us tools to inspect and reason about our addresses. It provides methods for looking at all the different parts of an email address, including things you likely won&amp;#x2019;t care about like the phrase or the comment.\n
  19. If we want to do something with our addresses before sending them, e.g. to enforce some sort of policy or business logic, Email::Address gives us tools to inspect and reason about our addresses. It provides methods for looking at all the different parts of an email address, including things you likely won&amp;#x2019;t care about like the phrase or the comment.\n
  20. If we want to do something with our addresses before sending them, e.g. to enforce some sort of policy or business logic, Email::Address gives us tools to inspect and reason about our addresses. It provides methods for looking at all the different parts of an email address, including things you likely won&amp;#x2019;t care about like the phrase or the comment.\n
  21. If we want to do something with our addresses before sending them, e.g. to enforce some sort of policy or business logic, Email::Address gives us tools to inspect and reason about our addresses. It provides methods for looking at all the different parts of an email address, including things you likely won&amp;#x2019;t care about like the phrase or the comment.\n
  22. If we want to do something with our addresses before sending them, e.g. to enforce some sort of policy or business logic, Email::Address gives us tools to inspect and reason about our addresses. It provides methods for looking at all the different parts of an email address, including things you likely won&amp;#x2019;t care about like the phrase or the comment.\n
  23. Just a sampling of the methods, again. \n
  24. Just a sampling of the methods, again. \n
  25. Just a sampling of the methods, again. \n
  26. \n
  27. There&amp;#x2019;s lots of different tools for dealing with email messages. They have varying amounts of development behind them and going into them presently. We&amp;#x2019;re focusing on Email::MIME because it works with other tools and it&amp;#x2019;s pretty solid overall.\n
  28. There&amp;#x2019;s lots of different tools for dealing with email messages. They have varying amounts of development behind them and going into them presently. We&amp;#x2019;re focusing on Email::MIME because it works with other tools and it&amp;#x2019;s pretty solid overall.\n
  29. There&amp;#x2019;s lots of different tools for dealing with email messages. They have varying amounts of development behind them and going into them presently. We&amp;#x2019;re focusing on Email::MIME because it works with other tools and it&amp;#x2019;s pretty solid overall.\n
  30. There&amp;#x2019;s lots of different tools for dealing with email messages. They have varying amounts of development behind them and going into them presently. We&amp;#x2019;re focusing on Email::MIME because it works with other tools and it&amp;#x2019;s pretty solid overall.\n
  31. \n
  32. These are some of the common methods that you&amp;#x2019;ll see in every day use. I&amp;#x2019;ve only got 20 minutes to cover a number of tools. RTFM.\n
  33. These are some of the common methods that you&amp;#x2019;ll see in every day use. I&amp;#x2019;ve only got 20 minutes to cover a number of tools. RTFM.\n
  34. These are some of the common methods that you&amp;#x2019;ll see in every day use. I&amp;#x2019;ve only got 20 minutes to cover a number of tools. RTFM.\n
  35. These are some of the common methods that you&amp;#x2019;ll see in every day use. I&amp;#x2019;ve only got 20 minutes to cover a number of tools. RTFM.\n
  36. These are some of the common methods that you&amp;#x2019;ll see in every day use. I&amp;#x2019;ve only got 20 minutes to cover a number of tools. RTFM.\n
  37. So what do we have here? The boilerplate at the top is pretty obvious. We call the create method on Email::MIME and it builds us an object with the given data. We use the header_str parameter to the create constructor instead of header as we&amp;#x2019;re specifying characters, not bytes.\n\nYou are working in characters, right?\n\nThen there&amp;#x2019;s the body parameter. It&amp;#x2019;s pretty simple.\n\nSo you might be wondering what strictures is. Basically it&amp;#x2019;s strict with a bunch of other stuff added in.\n
  38. This looks more or less like what you&amp;#x2019;d expect. To keep the example simple we didn&amp;#x2019;t specify a message-id. A sane MTA will append one when sending a message without one, the same for the date. \n
  39. Okay, awesome. We&amp;#x2019;ve made sure our email addresses are valid and deliverable. We&amp;#x2019;ve analyzed them to do any introspection or policy enforcement on them. We&amp;#x2019;ve created a message and filled it with a complicated DAG of attachments. But this is all academic if we can&amp;#x2019;t actually send the message. Here&amp;#x2019;s where Email::Sender comes into play.\n
  40. Okay, awesome. We&amp;#x2019;ve made sure our email addresses are valid and deliverable. We&amp;#x2019;ve analyzed them to do any introspection or policy enforcement on them. We&amp;#x2019;ve created a message and filled it with a complicated DAG of attachments. But this is all academic if we can&amp;#x2019;t actually send the message. Here&amp;#x2019;s where Email::Sender comes into play.\n
  41. Okay, awesome. We&amp;#x2019;ve made sure our email addresses are valid and deliverable. We&amp;#x2019;ve analyzed them to do any introspection or policy enforcement on them. We&amp;#x2019;ve created a message and filled it with a complicated DAG of attachments. But this is all academic if we can&amp;#x2019;t actually send the message. Here&amp;#x2019;s where Email::Sender comes into play.\n
  42. Okay, awesome. We&amp;#x2019;ve made sure our email addresses are valid and deliverable. We&amp;#x2019;ve analyzed them to do any introspection or policy enforcement on them. We&amp;#x2019;ve created a message and filled it with a complicated DAG of attachments. But this is all academic if we can&amp;#x2019;t actually send the message. Here&amp;#x2019;s where Email::Sender comes into play.\n
  43. Okay, awesome. We&amp;#x2019;ve made sure our email addresses are valid and deliverable. We&amp;#x2019;ve analyzed them to do any introspection or policy enforcement on them. We&amp;#x2019;ve created a message and filled it with a complicated DAG of attachments. But this is all academic if we can&amp;#x2019;t actually send the message. Here&amp;#x2019;s where Email::Sender comes into play.\n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n