Tornado Class Library

Special Topic - Email

Tornado send SMTP mail using DotNet Web.Mail class. The E-mail parameters are set in the dbMail property. The E-mail body can be either plain text/html or a template file. ASPdbSendMail supports bulk mail and can also attach files as well as Mailing list stored in various databases. Many options to make it a functional Email tool like send delay, bad address detection, batch size etc. MagicEmail here refers to the top of the line option in using the DB to supply all the parameters including an Email Body which is processed by the MagicCell filter.

Email is used as Stand Alone and in  Upload and Edit (Notification).

 

Standalone mode Obj.ASPdbSendMail
The Standalone mode initialize all the properties and execute send mail using the dbMail properties. See the example in sending plain mail.
Integrated mode Obj.ASPdbSendMail(False)
The Integrated mode does not initialize any properties and instead inherit all the properties and variables of the same unit. See the example in using the [[Grid]] as Mail.Body.
Upload
  • up.dbUpload = "Files=2| Label=Filename # | Width=50| SavePath=c:\temp"
  • up.dbMail = "From=support@aspdb.com | To=me@fkw.us | Subject=Upload notification |SMTPserver=mail.someserver.com"
Edit Add
  • Obj.EditAddFlds="...."
  • Obj.dbMail = "From=Me@MyUrl.com |To=You@YourUrl.com;#2#| Subject=My Subject at (" & Now() & ")| Body=My Message body|TestRun=false| trigger=add|SMTPServer=mail.YourServer.com"

 

Example - Send Plain HTML Text as the Email body

Setup all user inputs in dbMail property and send plain email. The Mail body is simple text included in the dbMail property. You can use dbInvisible=true to hide bulky grid display.

<script language="vb" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
 Dim m As New Tornado.Z()
 M.dbUnit=1
 m.dbMail = "From=FromMe@fkw.us | To=you@youraddress.com; you@youraddress1.com | Subject=My Subject | 
             Body=<b>Hello this is a plain email</b> |Visual=2 | TestRun=true| lapse=1 "
 m.ASPdbSendMail()
End Sub
</script>
 
Example - Send a file as Email text

This example extends the previous one by using a text file as body text. Note that File=Path can be either virtual or local path. Using local path will provide more security as the file can be accessed within the site's url.

<script language="vb" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
  Dim m As New Tornado.Z() 
  m.dbUnit=5 
  m.dbMail = "From=FromMe@fkw.us | To=frank@fkw.us; Kwong@fkw.us | Subject=My Subject | 
              Body=File=/site/tor/manual04/code/sales1.data |Visual=2 | TestRun=true| Lapse=1" 
  m.ASPdbSendMail() 
End Sub
</script>

 

 

Example - Send the entire grid as the Email body

A grid is generated in Unit 1 Use dbInvisible=true to hide bulky grid display. ASPdbSendTemplate is a method that is under ASPdbNet. That means after all the ASPdbNet work is done, user can decide what to keep for the subsequent operations like Send Email. In this example, we ask ASPdbSendTemplate to send the [[Grid]] generated by ASPdbNet to [[Email]] for processing. Finally, dbSendMail perofrm it's task according to the dbMail setup with the [[Mail]] macro will be replaced by the [[Grid]].

<script language="vb" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
  Dim addr As String
  Dim Myself As String = Request.ServerVariables("SCRIPT_NAME")
  If Not IsNothing(Request.Form("address")) Then addr = Request.Form("address")
  If addr <> "" Then
    Dim m As New Tornado.Z()
    m.dbQP = "u=1| dsn=nwind | sql=Select * from Orders | GridDisplayFlds=0,1,2,3| skin=1| invisible=false"
    m.dbMail = "From=support@aspdb.com | To=" & addr & "| Subject=Email Test | Body=[[Email]] |Visual=2 | TestRun=true"
    m.ASPdbNET()
    m.ASPdbSendTemplate("email","" , "[[Grid]]")
    m.ASPdbSendMail(false)
  End If
  Response.Write("<H3>Send Yourself a Report</H3>")
  Response.Write("<FORM NAME='TEST' METHOD='POST' Action='" & Myself & "'>")
  Response.Write("Your Email Address: <INPUT Name='address' Type='text'> <INPUT TYPE='submit' VALUE='Send'><BR>")
  Response.Write("</FORM>")
End Sub
</script>

 

Example - Send DB data as Email text

This example send data in a DB table. Each table record contains the destination Email Addresses. First we build a simple CSV file as the email data source to illustrate the very powerful and flexible SQL option -

 

Title FirstName LastName Email Sales
Mr. Frank Kwong frank@fkw.us 12345
Ms. Jane Doe Jane@fkw.us 23456
Mr. John Doe John@fkw.us 34567
Mrs. Mary Uno Mary@fkw.us 45678
Dr. Moon Pak Moon@fkw.us 78900

 

Cut and paste this file as c:\inetpub\wwwroot\tornado\DB\Email.csv
Title,LastName,FirstName,Email,Sales
Mr.,Frank,Kwong,frank@fkw.us,12345
Ms.,Jane,Doe,Jane@fkw.us,23456
Mr.,John,Doe,John@fkw.us,34567
Mrs.,Mary,Uno,Mary@fkw.us,45678
Dr.,Moon,Pak,Moon@fkw.us,78900
Test Csv Source
<script language="vb" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
  Dim EM As New Tornado.Z() 
   with EM 
    .dbQP = "U=1| S=1|PS=-1| Ni=none| SQL = Select * From Email.Csv| Pv=ODBC| Dt=TEXT"
    .dbDSN = "/tornado/db") 
    .ASPdbNet() 
   end with 
End Sub
</script>

 

Email - DB

Use the DB email field #3# as the 'To' addresses and use a 'fixed' Body. (Most common practice)
A batchsize of 2 is for illustration purpose only. Usually batchsize = 1 is used to make it more personal. Visual=2 will show all.
 

<script language="vb" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim Letter0 As String = "This is a fixed template body for non Magic Emails"
  Dim m As New Tornado.z
  m.dbQP = "U=1| S=1|PS=-1| Ni=none| Pv=ODBC| Dt=TEXT"
  m.dbDSN = "/tornado/db"
  m.dbMail = "SMTPServer=smtp.outserver.net| from=me@aspdb.com| to=#3# | " & _
    "SQLto=Select * From Email.Csv| Batchsize=2| Subject=Sales letter| " & _
    "IgnoreError = true | Visual = 2 | TestRun = true | Body = " & Letter0
  m.ASPdbSendMail()
End Sub
</script>

 

Email - Attachments
<Script language="vb" runat="server">
Dim Letter As String = "To: #2# #3#<br>From: The Boss<br>Subject: " & _
  "July Sales Distribution<P>Your sales for July is #4::currency#."
Sub Page_Load(Source as Object, E as EventArgs)
  Dim m As New Tornado.Z()
  m.dbQP = "U=1| S=1|PS=-1| Ni=none| Pv=ODBC| Dt=TEXT" 
  m.dbDSN = "/tornado/db"
  m.dbMail = "attach=c:\inetpub\wwwroot\tornado\manual\ex\image1.gif;" & _
    "c:\inetpub\wwwroot\tornado\manual\ex\image2.gif | from=TheBoss@fkw.us|" & _
    "to=#3# | SQLto=Select * From Email.Csv| Batchsize=0| " & _
    "Subject=July sales letter| IgnoreError = true | Visual = 2 |" & _
    " TestRun = true | Body = " & Letter"
  m.ASPdbSendMail()
End Sub
</script>

Send comments on this topic.

Copyright 1998-2006 ASP-db