Chapter Objectives - PowerPoint PPT Presentation

About This Presentation
Title:

Chapter Objectives

Description:

MailFormat enumeration - format. MailFormat.Html, MailFormat.Text ... MM.BodyFormat = MailFormat.Text. MM.Priority = MailPriority.Normal ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 76
Provided by: kathlee78
Category:

less

Transcript and Presenter's Notes

Title: Chapter Objectives


1
(No Transcript)
2
Chapter Objectives
3
Sending E-Mail from the Web Application
  • Security and Privacy Issues Related to E-mail
  • HTML-based
  • Viruses
  • Spam
  • Authorized users send e-mail

4
The E-Mail Server
  • E-mail server - SMTP server
  • Simple Mail Transfer Protocol (SMTP)
  • Protocol, or set of rules
  • Used to transfer mail between servers
  • Default folders
  • Pickup, Queue, Badmail, Drop, Route, Mailbox,
    SortTemp
  • C\InetPub\MailRoot
  • Verify the service is running
  • Administrative Tools - Open Services
  • Runs on port 25

5
The E-Mail Server (continued)
6
Configuring the E-Mail Server
  • Use MMC
  • Default SMTP Virtual Server
  • General Tab
  • Log Files
  • C\WINDOWS\Sytem32\Logiles\SmtpSvc1\
  • W3C Extended Log File Format
  • Advanced button - IP address

7
Configuring the E-Mail Server (continued)
8
Configuring the E-Mail Server (continued)
  • Access Tab
  • Authentication button
  • Anonymous access
  • Basic authentication
  • Integrated Windows Authentication
  • Similar to IIS

9
Configuring the E-Mail Server (continued)
10
Configuring the E-Mail Server (continued)
  • Messages Tab
  • Size of message
  • Session size
  • Total size of all the message body sections
    within a single connection
  • Number of messages per connection
  • Number of recipients per connection
  • E-mail address for Non-delivery Report
  • C\Inetpub\mailroot\Badmail

11
Configuring the E-Mail Server (continued)
12
Configuring the E-Mail Server (continued)
  • Delivery Tab
  • How the message is delivered
  • If cant be sent - number of minutes to wait
    before resend
  • Outbound Security
  • Configure users and authentication
  • Require encryption (TLS) - more secure then SSL
  • Outbound Connections
  • Limit number of messages, time-out
  • Limit number of connections per domain
  • Change port number

13
Configuring the E-Mail Server (continued)
14
Configuring the E-Mail Server (continued)
  • Advanced Figure 12-8
  • Configure servers that can send or relay messages
  • Prevent invalid domain address in Mail From line
    using Masquerade domain
  • Hop count - number of servers permitted to pass
    through
  • Smart host - a virtual server which may be more
    direct or less costly than sending it directly to
    a domain

15
Configuring the E-Mail Server (continued)
16
Configuring the E-Mail Server (continued)
  • LDAP Routing Tab
  • Lightweight Directory Access Protocol
  • Primary protocol for Active Directory
  • Directory service that stores information about
    objects on a network
  • Security Tab
  • Who can change settings - default administrators
    group
  • Only trusted users to alter settings
  • Domains
  • E-mail at tarastore.com and tarastore.net sent to
    same server

17
Configuring the E-Mail Server (continued)
18
Configuring the E-Mail Server (continued)
19
E-Mail Objects
  • .NET Mail classes
  • CDONTS Objects - communicate with SMTP server
  • C\WINDOWS\system32\cdonts.dll
  • Places message in the Pickup folder - or by hand
  • SMTP places message into Queue folder
  • If local recipient - places into Drop folder
  • If remote account - sends message to another
    server
  • If rejected or returned, places in Badmail folder
  • Creates Non-Delivery report (NDR)

20
E-Mail Objects (continued)
21
The .NET Mail Classes
  • System.Web.Mail namespace
  • MailMessage class - construct an email message
  • MailAttatchment class - identify a file
    (attachments)
  • SmtpMail class - send the e-mail message

22
The MailMessage Class Properties
  • MailFormat enumeration - format
  • MailFormat.Html, MailFormat.Text
  • MailPriority enumeration - importance
  • MailMessage.Normal, MailMessage.High,
    MailMessage.Low
  • MailAttachment class - construct an e-mail
    attachment
  • Filename - attachment location as string - drive,
    path, filename
  • MailMessage.Attachments - list of attachments
  • MailEncoding enumerator
  • MailEncoding.UUEncode default
  • MailEncoding.Base64 - binary encoding such as
    graphics

23
The MailMessage Class Properties (continued)
  • MailMessage.To - recipient multiple recipients
    separated with semi-colon
  • MailMessage.From - address of the sender
  • MailMessage.Subject - subject line
  • MailMessage.Body - body
  • MailMessage.Cc - a semicolon-delimited list
  • MailMessage.Bcc - semicolon-delimited list
  • MailMessage.UrlContentBase - URL base of all
    relative URLs used within the HTML - encoded body
  • MailMessage.UrlContentLocation - identify the
    location of content within message

24
The MailMessage Class Properties (continued)
  • SmtpServer change the SMTP Server from default
    SMTP Virtual Server to another server
  • Send method creates the message
  • Writes it to the Pickup folder
  • Eventually its moved to the Queue folder
  • SmtpMail.Send("sender_at_sender.com",
  • "recipient_at_recipient.com", "Subject", "Message")

25
Sending an E-Mail Message from an ASP.NET Web
Page
  • Create Chapter12 project and import files
  • Email_SendSingleMessage.aspx
  • Import namespaces
  • Imports System.Web.Mail
  • Create mail object, set properties, send message
  • Release variables
  • View page in the browser
  • View message in Drop folder
  • Folder varies with your system

26
Sending an E-Mail Message from an ASP.NET Web
Page (continued)
  • Dim MM As New MailMessage()
  • MM.From "your_email_at_your_address.edu"
  • MM.To "your_email_at_your_address.edu"
  • MM.Subject "CDONTS Exercise"
  • MM.Body "I have completed the CDONTS exercise"
  • MM.BodyFormat MailFormat.Text
  • MM.Priority MailPriority.Normal
  • SmtpMail.SmtpServer "Server name"
  • SmtpMail.Send(MM)
  • MM Nothing

27
Sending an E-Mail Message from an ASP.NET Web
Page (continued)
28
Troubleshooting E-Mail Messages
  • The SendUsing configuration value is invalid"
  • Solution
  • Reconfigure the SMTP settings programmatically
    and assign a server name before the message is
    sent.
  • "The server rejected one or more recipient
    addresses."
  • Unable to relay for your-email_at_your_address.edu
  • Solution
  • Change relay settings - allow your server to
    relay messages
  • Only allow messages from your computer to relay
    messages
  • Use exception handling and error messages
  • Read Non-Delivery report (NDR)

29
Troubleshooting E-Mail Messages (continued)
30
Troubleshooting E-Mail Messages (continued)
31
Troubleshooting E-Mail Messages (continued)
32
Storing and Retrieving Data in the Web Servers
File System
  • System.IO namespace
  • Interact with the file system
  • Classes
  • File, FileStream, and Directory
  • To create, read, and delete files
  • Newer classes FileSystemInfo
  • Access to DirectoryInfo and FileInfo classes
  • View Class Browser Application

33
Storing and Retrieving Data in the Web Servers
File System (continued)
34
Working with Directories
  • DirectoryInfo class
  • Access to properties
  • Dim DD As DirectoryInfo _
  • New DirectoryInfo("C\Inetpub\wwwroot\Chap
    ter12\")
  • Label1.Text DD.FullName
  • Other properties
  • Attributes, CreationTime, Exists
  • LastAccessTime, LastWriteTime
  • FullName, Extension, Name, Parent, and Root

35
Working with Directories (continued)
  • Iterate through DirectoryInfo
  • Dim MySubDirList As String
  • Dim SubDir As DirectoryInfo
  • For Each SubDir In DD.GetDirectories()
  • MySubDir SubDir.Name "ltbr /gt"
  • Label2.Text MySubDirList
  • Next

36
Working with Directories (continued)
  • Iterate through FileInfo
  • Dim MyFileList, MyPath As String
  • MyPath TextBox1.Text
  • Dim MyFile As FileInfo
  • For Each MyFile In DFL.GetFiles
  • Select Case MyFile.Extension
  • Case ".aspx"
  • MyFileList _
  • "lta href'" MyFile.Name "'gt" _
  • MyFile.Name "lt/agtltbr /gt"
  • Case ".vb", ".resx"
  • Case Else
  • MyFileList MyFile.Name "ltbr /gt"
  • End Select
  • Next
  • Label3.Text MyFileList

37
Working with Directories (continued)
  • DisplayChapter12Dir.aspx
  • DisplayDirectoryInfo function
  • Dim DD As DirectoryInfo _
  • New DirectoryInfo(MyPath)
  • lbl1.Text DD.FullName
  • lbl2.Text DD.Name
  • lbl3.Text DD.Attributes
  • lbl4.Text DD.CreationTime.ToShortDateString
  • lbl5.Text DD.LastAccessTime.ToShortDateString
  • lbl6.Text DD.LastWriteTime.ToShortDateString
  • lbl7.Text DD.Root.Name
  • lbl8.Text DD.Parent.Name
  • lbl9.Text DD.Exists
  • lbl10.Text GetLength(DirSize(DD))

38
Working with Directories (continued)
39
Working with Directories (continued)
40
Working with Directories (continued)
41
Creating and Deleting Directories
  • DirectoryInfo - to create and delete directories
  • CreateSubdirectory method - create a new
    directory
  • Pass the name of the directory
  • CreateDir.aspx
  • Buttons to create and delete directories
  • DisplayDirectory function
  • Retrieve the Users subdirectory list
  • c\Inetpub\wwwroot\Chapter12\Users

42
Creating and Deleting Directories (continued)
  • System.Exception
  • System.IO
  • IOException
  • DirectoryNotFoundException - directory does not
    exist
  • PathTooLongException - exceeds 248 characters
  • FileNotFoundException
  • Security.SecurityException - dont have
    permission
  • System.ArgumentException
  • Create a directory with invalid characters ltgt?
    or \\

43
Creating and Deleting Directories (continued)
  • Dim DDL As DirectoryInfo _
  • New DirectoryInfo(MyPath)
  • Dim SubDir As DirectoryInfo
  • Dim MyHash As New Hashtable
  • For Each SubDir In DDL.GetDirectories()
  • MyHash.Add(SubDir.Name, SubDir.Name)
  • Next
  • DropDownList1.DataTextField "Key"
  • DropDownList1.DataValueField "Value"
  • DropDownList1.DataSource MyHash
  • DropDownList1.DataBind()

44
Working with Directories (continued)
  • btnCreate_Click procedure
  • Dim DD As DirectoryInfo _
  • New DirectoryInfo(MyPath)
  • DD.CreateSubdirectory(TextBox1.Text)
  • btnDelete_Click procedure
  • Dim DD2 As DirectoryInfo _
  • New DirectoryInfo(MyPath _
  • DropDownList1.SelectedItem.ToString)
  • Label1.Text "The ltbgt" _
  • DropDownList1.SelectedItem.ToString _
  • " lt/bgtdirectory was deleted."
  • DD2.Delete()

45
Working with Directories (continued)
46
Creating and Reading Files from an ASP.NET Page
  • FileInfo class
  • Common Properties
  • Attributes, CreationTime, LastAccessedTime,
    LastWriteTime
  • Name, FullName, and Exists
  • Attributes (Right click on file and select
    Properties)
  • Hidden, Archive, ReadOnly, System
  • Methods
  • CopyTo, MoveTo, Delete
  • CreateText method
  • Returns StreamWriter object and open file for
    editing
  • Create method
  • Wrapper for the functionality of File.Create
  • Uses FileStream object not StreamWriter object

47
Creating a Text File
  • CreateFile.aspx
  • btnCreate_Click - creates the FileInfo object
  • Create StreamWriter object to create the file and
    open it for writing
  • Dim MyFile As String MyPath TextBox1.Text
  • Dim MyFileInfo As FileInfo New FileInfo(MyFile)
  • Dim SW As StreamWriter File.CreateText(MyFile)

48
Creating a Text File (continued)
  • Write the contents to the file - Write and
    WriteLine
  • SW.Write("This file was ")
  • SW.WriteLine("created by ")
  • SW.Write("Your Name")
  • SW.Write(vbCrLf)
  • SW.WriteLine("on " Now.Date.ToShortDateString)
  • SW.WriteLine()
  • SW.WriteLine()
  • SW.Write(TextBox1.Text)
  • SW.Close()
  • MyFileInfo Nothing

49
Creating a Text File (continued)
  • btnDelete_Click event procedure
  • Label1.Text "The ltbgt" TextBox1.Text _
  • " lt/bgtfile was created successfully."
  • Dim MyFileInfo As FileInfo New FileInfo(MyFile)
  • Label1.Text "The ltbgt" _
  • DropDownList1.SelectedItem.ToString _
  • " lt/bgtfile was deleted."
  • MyFileInfo.Delete()
  • MyFileInfo Nothing

50
Creating a Text File (continued)
  • btnDisplay_Click
  • Retrieves file - FileInfo object and opens file
    with OpenText
  • Returns StreamReader object
  • ReadToEnd - reads entire file line by line until
    end of file
  • Dim MyFileInfo As FileInfo New FileInfo(MyFile)
  • Dim SR As StreamReader MyFileInfo.OpenText()
  • Label3.Text SR.ReadToEnd
  • SR.Close()
  • SR Nothing

51
Creating a Text File (continued)
52
Creating an HTML Page
  • CreateHTMLFile.aspx
  • Page_Load event hander - display default message
  • If Not Page.IsPostBack Then
  • HyperLink1.Text ""
  • Label3.Text _
  • "Enter the name of the HTML file to create."
  • End If

53
Creating an HTML Page (continued)
  • btnCreate_Click
  • Creates FileInfo, StreamWriter create file and
    open it
  • Dim MyFile As String MyPath TextBox1.Text
  • Dim MyFileInfo As FileInfo New FileInfo(MyFile)
  • HyperLink1.Text ""
  • Label1.Text "ltbgtThe file was created!lt/bgt"
  • Dim SW As StreamWriter File.CreateText(MyFile)

54
Creating an HTML Page (continued)
  • Insert content
  • SW.WriteLine("lthtmlgtltheadgt")
  • SW.WriteLine("lttitlegtCreating an HTML File ")
  • SW.WriteLine(TextBox1.Text)
  • SW.WriteLine("lt/titlegtlt/headgt")
  • SW.WriteLine("ltbodygt")
  • SW.WriteLine(TextBox2.Text)
  • SW.WriteLine("lthr /gtltbr /gtltbr /gtCreated on ")
  • SW.WriteLine(Now.Date.ToShortDateString)
  • SW.WriteLine("lt/bodygtlt/htmlgt")
  • SW.Close()

55
Creating an HTML Page (continued)
  • Set hyperlink properties
  • Reset label
  • MyFileInfo Nothing
  • HyperLink1.Text "Click here to read the HTML
    file!"
  • HyperLink1.NavigateUrl _
  • "http//localhost/Chapter12/Users/"
    TextBox1.Text
  • Label1.Text ""

56
Creating an HTML Page (continued)
  • btnDelete_Click event procedure delete file
  • Dim MyFile As String MyPath TextBox1.Text
  • Dim MyFileInfo As FileInfo New FileInfo(MyFile)
  • HyperLink1.Text ""
  • Label1.Text "ltbgtThe File was deleted!lt/bgt"
  • MyFileInfo.Delete()
  • MyFileInfo Nothing

57
Creating an HTML Page (continued)
58
Working with Alternative Platforms PDAs and
Mobile Devices
  • Web application for mobile devices
  • Wide range of hardware and software
  • Screen size, resolution, color, graphics,
    multimedia capabilities
  • Support scaled-down version of a browser, text
  • Main platforms Palm, Windows Pocket PC, Windows
    CE
  • Simulators for devices are available to
    developers
  • .NET Compact Framework runs portable and mobile
    devices
  • Develop client as stand-alone application

59
Creating a WML Document
  • Wireless Application Protocol (WAP)
  • Standard to program mobile device
  • Wireless S Protocol (WSP)
  • Within the WAP - a transport protocol that
    performs the same functions as HTTP for mobile
    devices
  • WAP standards Wireless Markup Language (WML)
  • To work with Web content
  • File extension .wml
  • Compaq and other devices are tested by Microsoft

60
Creating a WML Document (continued)
61
Creating a WML Document (continued)
62
Creating a WML Document (continued)
63
Building PDA and Mobile Applications in Visual
Studio .NET
  • System.Web.Mobile namespace (assembly)
  • Mobile Web Forms Controls
  • Mobile controls
  • System.Web.UI.MobileControls
  • Label control
  • System.Web.UI.MobileControls.Label
  • Mobile Internet Designer drag and drop controls
  • Mobile QuickStart
  • http//localhost/mobilequickstart/

64
Using Mobile Controls in an ASP.NET Application
  • Mobile Forms
  • Display on mobile devices supports
  • WML, compact HTML (cHTML), HTML 3.2
  • Mobile Web Page
  • System.Web.UI.MobileControls.MobilePage
  • Each Web page contains a register directive for
    registering the mobile tag controls with the
    mobile control namespace

65
Using Mobile Controls in an ASP.NET Application
(continued)
  • lt_at_ Page Language"vb" AutoEventWireup"false"
    Codebehind"MobileWebForm1.aspx.vb"
    Inherits"Chapter12Mobile.MobileWebForm1" gt
  • lt_at_ Register TagPrefix"mobile"
    Namespace"System.Web.UI.MobileControls"
    Assembly"System.Web.Mobile" gt

66
Creating a Mobile Form
  • MFDisplayList.aspx
  • Insert Label control
  • ID - lblStoreName, Font Trebuchet MS,
  • ForeColor - 004040, Alignment Center,
  • Bold - True, Text Tara Store Home Page
  • Add List control
  • Decoration - none, Font Trebuchet MS,
  • ForeColor - 004040

67
Creating a Mobile Form (continued)
  • Create array (ArrayList) AR1 in Page_Load event
    procedure
  • Dim AR1 As New ArrayList(4)
  • AR1.Add("Irish History")
  • AR1.Add("Irish Music")
  • AR1.Add("Travel in Ireland")
  • AR1.Add("Sports in Ireland")
  • List1.DataSource AR1
  • List1.DataBind()

68
Creating a Mobile Form (continued)
69
Creating a Mobile Form (continued)
  • Properties
  • Wrapping NoWarp to stop from wrapping
  • TextView change to scroll horizontally for
    large text
  • Paginate true - divide list into multiple pages
    use PagerStyle
  • PageLabel identifies number of pages available
  • NextPageText and PreviousPageText, PagerStyle
    elements
  • assign a text value to display in the window
  • PagerStyle PageLabel"Page 0 of 1"
  • PagerStyle NextPageText"Continue"
  • PagerStyle PreviousPageText"Back"

70
Creating a Mobile Form (continued)
  • Each card represented by a separate Mobile Form
  • Create a link control to other cards or another
    WML file
  • NavigateURL is used to identify links
  • pound sign is used to indicate internal link
  • Can insert scripts
  • Form Templates
  • reusable content like HeaderTemplate and
    FooterTemplate
  • Mobile Form controls - other controls
  • Paragraph, line break, Bold, Italic, Anchor

71
Creating Multiple Web Forms
  • MFHomePage.aspx
  • Insert Label control - format
  • Add List control - format
  • Add Form tag to the page
  • Add ObjectList control to Products Form - format
  • Add Form tag to the page
  • Add Image control to Products Form - format
  • Add Form tag to the page
  • Add PhoneCall control to Products Form - format
  • View HTML
  • Page_Load procedure - create hash tables and
    array lists and bind to controls

72
Creating Multiple Web Forms (continued)
73
Creating Multiple Web Forms (continued)
74
Summary
  • SMTP server is the default mail service
  • Access SMTP properties via System.Web.Mail
    namespace
  • MailMessage class provides sender and recipient
    data and message content
  • System.IO provides classes that interact with the
    file system
  • DirectoryInfo accesses directories and
    subdirectories
  • FileInfo accesses the file and create basic files
  • CreateText method returns StreamWriter object and
    open file for editing
  • Create method uses FileStream object and is a
    wrapper for the functionality of File.Create

75
Summary (continued)
  • Write method is used to write content to a file
  • WAP is standard to create programs on a mobile
    device
  • WML is XML compliant language to create mobile
    applications
  • ASP.NET Mobile Server controls contain Mobile
    Forms, a Web page that contains Mobile controls
  • Mobile controls inherit System.Web.UI.MobileContro
    ls.MobilePage
Write a Comment
User Comments (0)
About PowerShow.com