SlideShare una empresa de Scribd logo
1 de 10
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.

Más contenido relacionado

Similar a Mailing, the developer's eye view

Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET AttributesPooja Gaikwad
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributessonia 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 KotlinShahRushika
 
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; mailtrapKaty 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 2009Brendan Lim
 
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 firstMd. Aftab Uddin Kajal
 
14 asp.net session20
14 asp.net session2014 asp.net session20
14 asp.net session20Vivek chan
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With ElmBrian 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 IntroductionLearningTech
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010vchircu
 
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
 
Create an other activity lesson 3
Create an other activity lesson 3Create an other activity lesson 3
Create an other activity lesson 3Kalluri 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.pdfShaiAlmog1
 

Similar a 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
 

Más de 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 2015Violeta 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 OnlineVioleta Salas
 
Mobile Marketing and Social Campaigns
Mobile Marketing and Social CampaignsMobile Marketing and Social Campaigns
Mobile Marketing and Social CampaignsVioleta 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 CVioleta 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 1Violeta Salas
 
Self discipline - Brian Tracy
Self discipline - Brian TracySelf discipline - Brian Tracy
Self discipline - Brian TracyVioleta 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 IncVioleta 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ónVioleta 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 doVioleta Salas
 
Smart Business Architect
Smart Business ArchitectSmart Business Architect
Smart Business ArchitectVioleta Salas
 

Más de 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
 

Último

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

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.