SlideShare a Scribd company logo
Mailing   The developer’s eye view
          Microsoft.NET Framework
          Visual Basic



          Lessons:
          No.1 - Creating an E-Mail Message
          No.2 - Sending an E-Mail

                                Violeta Salas – Notes
Creating a MailMessage Object


There are 2 different constructors that allow you to create a MailMessage:

Visual Basic:
Dim m As MailMessage=New MailMessage (“jane@nmbusiness.com”,_
“ben@nmbusiness”, “Data Report”, “See the attached spreadsheet.”)

Dim m As MailMessage=New MailMessage _
(New MailAddress(“lance@md.com”, ”Lance Tucker”),_
New MailAdrress (“lance@md.com”, “Ben Miller”))
Adding MailAddress objects to
           the MailMessage.To property

Use the MailAddressCollection type to specify:
• MailMessage.From
• MailMessage.Subject
• MailMessage.Body
Dim m As MailMessage=New MailMessage()
m.From = New MailAddress (“lance@md.com”, ”Lance Tucker”)
m.To.Add(New MailAddress (“james@md.com”, “James van Eaton”))
m.To.Add(New MailAddress (“ben@md.com”, “Ben Miller”))
m.To.Add(New MailAddress (“burke@md.com”, “Burke Fewel”))
m.Subject=“Data Report”
m.Body=“See the attached spreadsheet.”
How to attach files

• Add it to the MailMessage.Attachments AttacmentCollection by calling
  the MailMessage.Attachments.Add method, the simplest way to add a
  file is to specify the filename:
   Dim m As MailMessage=New MailMessage ()
   m.Attachments.Add(New Attachment(“C:windowswin.ini”))

• You can also specify a Multipurpose Internet Mail Extensions (MIME)
  content type using the System.Net.Mime.MediaTypeNames
  enumeration. This requires Systema.IO and System.Net.Mime in
  addition to System.Net.Mail.
  Using Steam as a file attachment and how to specify the Mime type:
    Dim m As MailMessage=New MailMessage ()
    Dim sr As Stream= New FileStream("C:Attachment.txt", FileMode.Open, FileAccess.Read)
    m.Attachments.Add(New Attachment(sr, “myfile.txt”, MediaTypeNames.Application.Octet))
Creating HTML Emails


Supply HTML – tagged content for MailMessage.Body and set the
MailMessage.IsBodyHtml attribute to true:
Dim m As MailMessage=New MailMessage
m.From= new MailAddress(“lance@md.com”,”Lance Tucker”)
m.To.Add(New MailAddress(“burke@md.com”,”Burke Fewel”))
‘Specigy an HTML message body
m.Body= _
"<html><body><h1>My Message</h1><br>This is an HTML message.</body></html>"
m.IsBodyHTML=true
‘Send the message
Dim client As SmtpClient= New SmtpClient(“smtp.md.com”)
Client.Send(m)
To embed images into an
                       HTML message


They appear when the user clicks the message, use the AlternateView and
LinkedResource classes:
‘Create the HTML message body
‘Reference embedded images using the content ID

Dim htmlBody As String="<html><body><h1>Picture</h1><br>" + _
"<img src=""cid:Pic1""></body></html>“
Dim avHtml As AlternateView=AlternateView.CreateAlternateViewFromString(_
htmlBody, Nothing, MediaTypeNames.Text.Html)

‘Create a LinkedResource object for each embedded image
Dim pic1 As LinkedResource = New LinkedResource(_
   “pic.jpg”, MediaTypeNames.Images.Image.Jpeg)
Pic1.ContentId=“Pic1”
avHtml.LinkedResources.Add(pic1)
‘Create an alternate view for unsupported clients
Dim textBody As String= _
 "You must use an e-mail client that supports HTML messages“
Dim avText As AlternateView=AlternateView.CreateAlternateViewFromString(_
  textBody, Nothing, MediaTypeNames.Text.Plain)
‘Add the alternate views instead of using MailMessage.Body
Dim m As MailMessage= New MailMessage
m.AlternateViews.Add(avHtml)
m.AlternateViews.Add(avText)

‘Address and send the message
m.From= New MailAddress(“lance@md.com”,”Lance Tucker”)
m.To.Add(New MailAddress(“james@md.com”,”James van Eaton”))
m.Subject= “A picture using alternate views”
Dim client As SmtpClient = New SmtpClient(“smtp.md.com”)
Client.Send(m)
The code produces de HTML message
shown.

- Figure: Using AlternateView and
  LinkedResource to embed images in an
  e-mail.
LAB:
                   Now you will generate an
                      E-Mail Message
Exercise: Create a MailMessage Object

In this exercise, you will create a MailMessage object based on user input
into a Microsoft Windows Forms application that is provided for you.
Lesson Summary

• To send an email message create a MailMessage Object, specify
    • Sender, Subject, Body
    And you can add recipients, alternate views and file attachments. Then
    create an instance of the SmtpClient class, and call SmtpClient.Send or
    SmtpCliente.SendAsync.

• The MailMessage object includes constructors that allow you to create
  simple messages, messages with multiple recipients requiere adding more
  code.

• To attac a file, create an instance of the Attachment class and add it to the
  MailMessage.Attachments collection.

• Creating an HTML message without image is as simple as specifying HTML
  in the body and setting MailMessage.IsBodyHtml to true. If you need to
  include images in the message, create an AlternateView object and a
  LinkedResource object for each image.

More Related Content

Similar to Mailing, the developer's eye view

Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
Pooja Gaikwad
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
sonia merchant
 
Send Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with KotlinSend Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with Kotlin
ShahRushika
 
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
 
Mobilizing Your Rails Application - LA Ruby Conference 2009
Mobilizing Your Rails Application - LA Ruby Conference 2009Mobilizing Your Rails Application - LA Ruby Conference 2009
Mobilizing Your Rails Application - LA Ruby Conference 2009
Brendan Lim
 
DOM and Events
DOM and EventsDOM and Events
DOM and Events
Julie Iskander
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code first
Md. Aftab Uddin Kajal
 
14 asp.net session20
14 asp.net session2014 asp.net session20
14 asp.net session20
Vivek chan
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With Elm
Brian Hogan
 
(CRUD) How To Connect To Microsoft Access Database Insert Update Delete Clear...
(CRUD) How To Connect To Microsoft Access Database Insert Update Delete Clear...(CRUD) How To Connect To Microsoft Access Database Insert Update Delete Clear...
(CRUD) How To Connect To Microsoft Access Database Insert Update Delete Clear...
mauricemuteti2015
 
Aspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csAspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csMurali G
 
Meteor + Ionic Introduction
Meteor + Ionic IntroductionMeteor + Ionic Introduction
Meteor + Ionic Introduction
LearningTech
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
vchircu
 
ASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CSASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CStutorialsruby
 
ASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CSASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CStutorialsruby
 
Teamwork
TeamworkTeamwork
Create an other activity lesson 3
Create an other activity lesson 3Create an other activity lesson 3
Create an other activity lesson 3
Kalluri Vinay Reddy
 
Creating an Uber Clone - Part XXXX - Transcript.pdf
Creating an Uber Clone - Part XXXX - Transcript.pdfCreating an Uber Clone - Part XXXX - Transcript.pdf
Creating an Uber Clone - Part XXXX - Transcript.pdf
ShaiAlmog1
 

Similar to Mailing, the developer's eye view (20)

Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
 
Send Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with KotlinSend Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with Kotlin
 
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
 
4.C#
4.C#4.C#
4.C#
 
Mobilizing Your Rails Application - LA Ruby Conference 2009
Mobilizing Your Rails Application - LA Ruby Conference 2009Mobilizing Your Rails Application - LA Ruby Conference 2009
Mobilizing Your Rails Application - LA Ruby Conference 2009
 
DOM and Events
DOM and EventsDOM and Events
DOM and Events
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code first
 
14 asp.net session20
14 asp.net session2014 asp.net session20
14 asp.net session20
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With Elm
 
(CRUD) How To Connect To Microsoft Access Database Insert Update Delete Clear...
(CRUD) How To Connect To Microsoft Access Database Insert Update Delete Clear...(CRUD) How To Connect To Microsoft Access Database Insert Update Delete Clear...
(CRUD) How To Connect To Microsoft Access Database Insert Update Delete Clear...
 
Aspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csAspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_cs
 
Meteor + Ionic Introduction
Meteor + Ionic IntroductionMeteor + Ionic Introduction
Meteor + Ionic Introduction
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
ASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CSASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CS
 
ASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CSASPNET_MVC_Tutorial_06_CS
ASPNET_MVC_Tutorial_06_CS
 
Teamwork
TeamworkTeamwork
Teamwork
 
Create an other activity lesson 3
Create an other activity lesson 3Create an other activity lesson 3
Create an other activity lesson 3
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
Creating an Uber Clone - Part XXXX - Transcript.pdf
Creating an Uber Clone - Part XXXX - Transcript.pdfCreating an Uber Clone - Part XXXX - Transcript.pdf
Creating an Uber Clone - Part XXXX - Transcript.pdf
 

More from Violeta Salas

SEO Trends 2015 - Tendencias clave para lograr el éxito en este 2015
SEO Trends 2015 - Tendencias clave para lograr  el éxito en este 2015SEO Trends 2015 - Tendencias clave para lograr  el éxito en este 2015
SEO Trends 2015 - Tendencias clave para lograr el éxito en este 2015
Violeta Salas
 
PayU Latinaomerica Métodos de pago Online
PayU Latinaomerica Métodos de pago OnlinePayU Latinaomerica Métodos de pago Online
PayU Latinaomerica Métodos de pago Online
Violeta Salas
 
Mobile Marketing and Social Campaigns
Mobile Marketing and Social CampaignsMobile Marketing and Social Campaigns
Mobile Marketing and Social Campaigns
Violeta Salas
 
Mobile marketing & Business
Mobile marketing & Business Mobile marketing & Business
Mobile marketing & Business
Violeta Salas
 
Class 02 Objective C
Class 02   Objective CClass 02   Objective C
Class 02 Objective C
Violeta Salas
 
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Violeta Salas
 
Self discipline - Brian Tracy
Self discipline - Brian TracySelf discipline - Brian Tracy
Self discipline - Brian Tracy
Violeta Salas
 
Inspirational lessons from Steve Jobs Founder of Apple Inc
Inspirational lessons from Steve Jobs Founder of Apple IncInspirational lessons from Steve Jobs Founder of Apple Inc
Inspirational lessons from Steve Jobs Founder of Apple Inc
Violeta Salas
 
Como integrar social media en su Organización
Como integrar social media en su OrganizaciónComo integrar social media en su Organización
Como integrar social media en su Organización
Violeta Salas
 
Find your true passion and do what you love to do
Find your true passion and do what you love to doFind your true passion and do what you love to do
Find your true passion and do what you love to do
Violeta Salas
 
Smart Business Architect
Smart Business ArchitectSmart Business Architect
Smart Business Architect
Violeta Salas
 

More from Violeta Salas (12)

SEO Trends 2015 - Tendencias clave para lograr el éxito en este 2015
SEO Trends 2015 - Tendencias clave para lograr  el éxito en este 2015SEO Trends 2015 - Tendencias clave para lograr  el éxito en este 2015
SEO Trends 2015 - Tendencias clave para lograr el éxito en este 2015
 
PayU Latinaomerica Métodos de pago Online
PayU Latinaomerica Métodos de pago OnlinePayU Latinaomerica Métodos de pago Online
PayU Latinaomerica Métodos de pago Online
 
Mobile Marketing and Social Campaigns
Mobile Marketing and Social CampaignsMobile Marketing and Social Campaigns
Mobile Marketing and Social Campaigns
 
Mobile marketing & Business
Mobile marketing & Business Mobile marketing & Business
Mobile marketing & Business
 
Class 02 Objective C
Class 02   Objective CClass 02   Objective C
Class 02 Objective C
 
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
Apples’ iPhone, iPod touch and iPad Application Programming - CLASS 1
 
Self discipline - Brian Tracy
Self discipline - Brian TracySelf discipline - Brian Tracy
Self discipline - Brian Tracy
 
Inspirational lessons from Steve Jobs Founder of Apple Inc
Inspirational lessons from Steve Jobs Founder of Apple IncInspirational lessons from Steve Jobs Founder of Apple Inc
Inspirational lessons from Steve Jobs Founder of Apple Inc
 
Como integrar social media en su Organización
Como integrar social media en su OrganizaciónComo integrar social media en su Organización
Como integrar social media en su Organización
 
Find your true passion and do what you love to do
Find your true passion and do what you love to doFind your true passion and do what you love to do
Find your true passion and do what you love to do
 
Winning Customers
Winning CustomersWinning Customers
Winning Customers
 
Smart Business Architect
Smart Business ArchitectSmart Business Architect
Smart Business Architect
 

Recently uploaded

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
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
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
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
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.
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
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
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
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
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 

Recently uploaded (20)

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
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
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
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
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
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
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
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
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
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 

Mailing, the developer's eye view

  • 1. Mailing The developer’s eye view Microsoft.NET Framework Visual Basic Lessons: No.1 - Creating an E-Mail Message No.2 - Sending an E-Mail Violeta Salas – Notes
  • 2. Creating a MailMessage Object There are 2 different constructors that allow you to create a MailMessage: Visual Basic: Dim m As MailMessage=New MailMessage (“jane@nmbusiness.com”,_ “ben@nmbusiness”, “Data Report”, “See the attached spreadsheet.”) Dim m As MailMessage=New MailMessage _ (New MailAddress(“lance@md.com”, ”Lance Tucker”),_ New MailAdrress (“lance@md.com”, “Ben Miller”))
  • 3. Adding MailAddress objects to the MailMessage.To property Use the MailAddressCollection type to specify: • MailMessage.From • MailMessage.Subject • MailMessage.Body Dim m As MailMessage=New MailMessage() m.From = New MailAddress (“lance@md.com”, ”Lance Tucker”) m.To.Add(New MailAddress (“james@md.com”, “James van Eaton”)) m.To.Add(New MailAddress (“ben@md.com”, “Ben Miller”)) m.To.Add(New MailAddress (“burke@md.com”, “Burke Fewel”)) m.Subject=“Data Report” m.Body=“See the attached spreadsheet.”
  • 4. How to attach files • Add it to the MailMessage.Attachments AttacmentCollection by calling the MailMessage.Attachments.Add method, the simplest way to add a file is to specify the filename: Dim m As MailMessage=New MailMessage () m.Attachments.Add(New Attachment(“C:windowswin.ini”)) • You can also specify a Multipurpose Internet Mail Extensions (MIME) content type using the System.Net.Mime.MediaTypeNames enumeration. This requires Systema.IO and System.Net.Mime in addition to System.Net.Mail. Using Steam as a file attachment and how to specify the Mime type: Dim m As MailMessage=New MailMessage () Dim sr As Stream= New FileStream("C:Attachment.txt", FileMode.Open, FileAccess.Read) m.Attachments.Add(New Attachment(sr, “myfile.txt”, MediaTypeNames.Application.Octet))
  • 5. Creating HTML Emails Supply HTML – tagged content for MailMessage.Body and set the MailMessage.IsBodyHtml attribute to true: Dim m As MailMessage=New MailMessage m.From= new MailAddress(“lance@md.com”,”Lance Tucker”) m.To.Add(New MailAddress(“burke@md.com”,”Burke Fewel”)) ‘Specigy an HTML message body m.Body= _ "<html><body><h1>My Message</h1><br>This is an HTML message.</body></html>" m.IsBodyHTML=true ‘Send the message Dim client As SmtpClient= New SmtpClient(“smtp.md.com”) Client.Send(m)
  • 6. To embed images into an HTML message They appear when the user clicks the message, use the AlternateView and LinkedResource classes: ‘Create the HTML message body ‘Reference embedded images using the content ID Dim htmlBody As String="<html><body><h1>Picture</h1><br>" + _ "<img src=""cid:Pic1""></body></html>“ Dim avHtml As AlternateView=AlternateView.CreateAlternateViewFromString(_ htmlBody, Nothing, MediaTypeNames.Text.Html) ‘Create a LinkedResource object for each embedded image Dim pic1 As LinkedResource = New LinkedResource(_ “pic.jpg”, MediaTypeNames.Images.Image.Jpeg) Pic1.ContentId=“Pic1” avHtml.LinkedResources.Add(pic1)
  • 7. ‘Create an alternate view for unsupported clients Dim textBody As String= _ "You must use an e-mail client that supports HTML messages“ Dim avText As AlternateView=AlternateView.CreateAlternateViewFromString(_ textBody, Nothing, MediaTypeNames.Text.Plain) ‘Add the alternate views instead of using MailMessage.Body Dim m As MailMessage= New MailMessage m.AlternateViews.Add(avHtml) m.AlternateViews.Add(avText) ‘Address and send the message m.From= New MailAddress(“lance@md.com”,”Lance Tucker”) m.To.Add(New MailAddress(“james@md.com”,”James van Eaton”)) m.Subject= “A picture using alternate views” Dim client As SmtpClient = New SmtpClient(“smtp.md.com”) Client.Send(m)
  • 8. The code produces de HTML message shown. - Figure: Using AlternateView and LinkedResource to embed images in an e-mail.
  • 9. LAB: Now you will generate an E-Mail Message Exercise: Create a MailMessage Object In this exercise, you will create a MailMessage object based on user input into a Microsoft Windows Forms application that is provided for you.
  • 10. Lesson Summary • To send an email message create a MailMessage Object, specify • Sender, Subject, Body And you can add recipients, alternate views and file attachments. Then create an instance of the SmtpClient class, and call SmtpClient.Send or SmtpCliente.SendAsync. • The MailMessage object includes constructors that allow you to create simple messages, messages with multiple recipients requiere adding more code. • To attac a file, create an instance of the Attachment class and add it to the MailMessage.Attachments collection. • Creating an HTML message without image is as simple as specifying HTML in the body and setting MailMessage.IsBodyHtml to true. If you need to include images in the message, create an AlternateView object and a LinkedResource object for each image.