首页 | 邮件资讯 | 技术教程 | 解决方案 | 产品评测 | 邮件人才 | 邮件博客 | 邮件系统论坛 | 软件下载 | 邮件周刊 | 热点专题 | 工具
网络技术 | 操作系统 | 邮件系统 | 客户端 | 电子邮箱 | 反垃圾邮件 | 邮件安全 | 邮件营销 | 移动电邮 | 邮件软件下载 | 电子书下载

邮件服务器

技术前沿 | Qmail | IMail | MDaemon | Exchange | Domino | 其它 | Foxmail | James | Kerio | JavaMail | WinMail | Sendmail | Postfix | Winwebmail | Merak | CMailServer | 邮件与开发 | 金笛 |
首页 > 邮件服务器 > 邮件与程序开发 > 使用ASPMail组件发送数字卡片 > 正文

使用ASPMail组件发送数字卡片

出处:5DMail收集整理 作者:未知(请作者联系) 时间:2005-12-27 9:20:00
Sending Digital PostCards with ASP and the free component ASPEmail from Persits software.
By Joao Vieira

What is a Digital Postcard?
A digital postcard is a image a net surfer picks out, along with an accompanying personal message. The net surfer "sends" the postcard by supplying a friend's email address. A link is then emailed to the address supplied. The link takes the receiver of the digital postcard to the site which displays the image and contains the personal message.



First you must create a database to house the information for the postcards. (I use a DataBase to put the PostCards information so that when a person gets the mail with the post card only have to click on the link and the page apears, goin to DB to get the Data. So here it is the structure of my DataBase (you can make your own, with more information if you intend to.


Postal
ID_POSTAL Autonumber
passw integer
postal Text
nameto Text
namefrom Text
emailfrom Text
emailto Text
Message Text
Data Text

For the digital postcard system to work, you will need a number of images for the postcards. In my example I have six unique postcards, and 12 images for the postcards: a thumbnail and normal size image for each postcard. I also use images for buttons, the main ones being View, Send, and Repeat.

Concerning the code, I want to warn you that I am not going to be going deep into the HTML aspect; I will concentrate on the ASP. If you have any questions about this article, please contact me.

You will have to make an HTML form. I used the POST method, because I don't like to see all ofthe information submitted in the address link box. (Related Article! Passing Data Between ASP Pages)

FILE: makin.html
This file contains the form where we get all of the information from the user. This information will be used to make the digital postcard.

<form  
     name="postalsent"  
     method="post"  
     action="view.asp?fromn=seeit"  
     target="_self"
>

.....
    <td width="24" valign="bottom">
       <font face="Arial">
         <input type="radio" value="postal1" name ="R1">
       </font>
    </td>

    <td width="140">
       <font face="Arial">
      <IMG border=2 height=86 src="images/postal1.gif" width=134>
       </font>
    </td>

    <td width="12" valign="bottom">
       <font face=3D"Arial">                 
          <input type="radio" value="postal2" name ="R1">
       </font>
    </td>

    <td width="151">
       <font face="Arial">
          <IMG border=2 height=87 src="images/postal2.gif" width=134>
       </font>
    </td>
  </tr>

  <tr>
    <td width="24" valign="bottom">
        <font face="Arial">
           <input type="radio" value="postal3" name="R1">
        </font>
    </td>

    <td width="140">
        <font face="Arial">
           <IMG border=2 height=88 src="images/postal3.gif" width=135>
        </font>
    </td>

    <td width="12" valign="bottom">
        <font face="Arial">
           <input type="radio" value="postal4" name="R1">
......




  <INPUT name="nameto" size=18 style="LEFT: 1px; TOP: 2px">
  <input name="emailto" size="18">
  <input name="namefrom" size="18">
  <input name="emailfrom" size="18">
  <TEXTAREA cols=18 name=message rows=2></TEXTAREA>
  <input type="image" name="bseeit" src="images/seesentbotton.gif"
      border=0 height=51 width=110>
   

   <td width="32%">
     <a href="makin.htm">
        <img border=0 height=53 src="images/resetbotton.gif" width=41>
     </a>
   </td>

......

As you see in this example I use an image for Submit Button, and another image for reset button, at the reset button I made a reload of the page (refresh) that really cleans all the fields.

At action="view.asp?fromn=seeit" I use fromn to know if view.asp is being accessed from the creation phase or from the person that wants to view the digital postcard that was sent to them. I chose to set fromn to Seeit if we are still in the creation phase, and out if we are wanting to view the postcard.

In the file makin.html all we want to do is to send the information collected in the above FORM. The fields that i'm using are the ones named above: R1, nameto, mailto, namefrom, emailfrom.

FILE: view.asp
This the the important part, here we will see if there is a person previewing the card before sending it, or a person viewing card already sent. We will take all the information sent by the POST form of the previous file.

<%
Dim fromn
Dim ident
Dim psw

' erring tells us if the card already
' exists.  By default, we assum it does.
Dim erring  

' I normaly use 0 and 1 for boolean,  
' cause it is quicker
erring = 0  


' Receiving the information    
' from the link that led to this file;
' this one tell us
' what kind of access we're doing
fromn = Request.QueryString("fromn")
  
' here we take the ID from the post card,  
' for us to know wich card we want to see.
' All this information will be compared with  
' the one in the database.
ident = Request.QueryString("ident")  


' This is the password
' We do not want a person that knows there exists a  
' postcard with ID 13 tries to see one with ID 12.
' We will generate a random number for the password
psw = Request.QueryString("psw")  

if fromn = "seeit" then  
     ' If we just want to see the preview
     ' I have created sessions to keep the information,
     ' so that I can view the data at any step
     session("postal") = Request.form("R1")
     session("namefrom") = Request.form("namefrom")
     session("emailfrom") = Request.form("emailfrom")

     session("nameto") = Request.form("nameto")
     session("emailto") = Request.form("emailto")
     session("message") = Request.form("message")
else  
     'Someone is wanting to see an already sent card

     'Open the DB connection
     Set Conn = Server.CreateObject("ADODB.Connection")

     ' The DSN you made for the database
     conn.open "DSN=postal;"  

     'Create a recordset
     Set rs = Server.CreateObject("ADODB.Recordset")  


     ' This is asimple SQL statement that see if the ID and  
     ' password are connected in the DB
     SQLStmt = "SELECT * FROM postal WHERE ID_POSTAL = " & _
               CInt(ident) & " AND passw = " & CInt(psw)

     ' Execute the SQL statementz
     rs.Open SQLstmt, Conn, 1, 2


     if rs.EOF then
      'Post card doesn't exist or invalid password!
         erring = 1  
     else  
      'Postcard does exist.  Populate the session
      'variables with the database info.
         session("postal") = rs("postal")
         session("namefrom") = rs("namefrom")
         session("emailfrom") = rs("emailfrom")
         session("nameto") = rs("nameto")
         session("emailto") = rs("emailto")
         session("message") = rs("message")
'if fromn have "seeit we will show =
     end if
end if
%>

<html>
<body
     marginheight="0"
     marginwidth="0"
     topmargin="0"
     leftmargin="0"
     background="images/something.gif"
     bgcolor="#002400"
     text="#FCC403"
>

<%
' At this time we will see if there has been an error
' We also want to make sure the form data is valid.

if erring <> 1 and (fromn="seeit" or fromn="out") and  
   session("postal") <> "" then

     ' if everything is correct we show the information
%>
<div align="left">
<table border="0" width="580" cellspacing="0" cellpadding="0">
  <tr>
    <td width="50%" valign="top" align="left"><br>
      <br>
      <img src="images/<%=session("postal")%>.jpg" hspace="5"
          border="2" WIDTH="354" HEIGHT="231">
    </td>
    <td width="50%">
       <table border="0" cellspacing="3" width="100%" cellpadding="3"
              bordercolor="#000000" height="202">
         <tr>
           <td width="100%" height="109">
              <p align="left">
              <font face="Arial"><br>
                <small>From:</small>
                <strong><%=session("namefrom")%></strong>
                <br>
                <small>Email:</small><small><strong>
                <%=session("emailfrom")%></strong></small>
                <br>
                <small>To:</small><strong><small>
                <%=session("nameto")%></small></strong>
                <br>
                <small>Email:</small><small><strong>
                <%=session("emailto")%></strong></small>
              </font>
            </td>
          </tr>

          <tr>
            <td width="100%">
              <font face="Arial">
                <small>Message:</small><br>
                <font size="2"><strong>
                <%=session("message")%></strong>
                </font>
              </font>
             </td>
          </tr>

          <tr>
            <td width="100%" align="center" valign="middle" height="29">
            <%
               'if fromn == "seeit" we will show the
            'buttons "to send" and "to retry"
               if fromn="seeit" then  
            %>
              <p align="left"><br>
              <a href="javascript:history.back()">
                <img src="images/rebuildbotton.gif" width="60"
                     height="53" border="0">
              </a>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <a href="enviado.asp">
                 <img src="images/sendbotton.gif" width="41"
                      height="53" border="0">
              </a>
             </td>
           </tr>
           </table>
         </td>
      </tr>
   </table>
</div>

           <%
            ' Someone is viewing a card already made
         ' Show the reply button  
            else  
           %>
              <br><br><br>
              <a href="makin.htm" target="_self" >
                 <img border="0" height="72" src="images/replybotton.gif"
                       width="176">
              </a>
           <%
            end if

' This else will only be reached if there is no card
' (i.e. the password was incorrect)  We need to show
' an error message.
else
%>  

<br><br>
<center>
  <img src="images/error.gif" width="322" height="53"
     border="0">
</center>
<br>

<%
end if    


' This is where i remove all the postcards  
' in the DB with more than 30 days old.

' I do not want to make a huge DB, so I clean  
' it just to have the messages of the last 30 days.

' You can now ask.. "-So, why did you put this code here?"
' My response is:
' "- Because this is the place where you fill the DB,
' so if you are going to put another record
' at the DB, lets clean some old stuff."

' That being said, let's clean the db!  :)

' Here we will get the system date (yes, the server date)
d = now()  

' We will decrease 30 days at the date we have
d = DateAdd("d",-30,d)

Set Conn = Server.CreateObject("ADODB.Connection")  
conn.open "DSN=postal;"

Set rs = Server.CreateObject("ADODB.Recordset")  

' Run a SQL query that will remove all out of date records
SQLStmt = "DELETE FROM postal WHERE data < #" & d & "#" '

'Run the query
rs.Open SQLstmt,Conn,1,2  
%>

</body>    
</html>


FILE: enviado.asp
At this time, we will validate all the information that it is supposed to sent as well as the data that we
will put in the DB. If everything is well we will send the information to the receiver by e-mail. I will
explain later how to get the free e-mail component, how to register it at the server, and how to use it.

<%

' This is the variable that I use to the ID  
' of the post card
Dim identifier

' goby is anotther  boolean to  
' see if there is an error in the data
Dim goby

goby = 1    'lets start it with True

%>

<html>
<body
     marginheight="0"
     marginwidth="0"
     topmargin="0"
     leftmargin="0"
     background="images/something.gif"
      bgcolor="#002400"
     text="#FCC403"
>

<font face=3D"Arial">
<small><strong>

<%
' Let's validate the name; the length of the
' name must be at least 2 characters long
if len(session("nameto")) < 2 then  
     ' So if there is any problem there will be an error  
     goby = 0  
end if


if len(session("namefrom")) < 2 then
     goby = 0
end if


' Validate the e-mail, I have written
' an arthicle about this, take a look at it
If Len(session("emailfrom")) <= 5 Then  
     goby = 0
Else
     If InStr(1, session("emailfrom"), "@", 1) < 2 Then
         goby = 0
     Else
         If InStr(1,session("emailfrom"), ".", 1) < 4 Then
            goby = 0
         End If
     End If
End If

If Len(session("emailto")) <= 5 Then
     goby = 0  
Else
     If InStr(1, session("emailto"), "@", 1) < 2 Then
         goby = 0
     Else
         If InStr(1,session("emailto"), ".", 1) < 4 Then
             goby = 0
         End If
     End If
End If


' Make sure the message is less than 500 characters.
If len(session("message")) >= 500 Then  
     goby = 0
End If


' If there are errors, then let the user know
' And make him/her correct the data
if goby = 0 then %>

   <br><br><br><br><br>
   <center>
      <img src="images/error.gif" width="322"  
           height="53" border="0">
   </center>
   <br>
<%
end if


' There are no errors.  Put the data in the DB
' and send the link to the receiver via email.
If goby = 1 then  
    Set Conn = Server.CreateObject("ADODB.Connection")
    conn.open"DSN=postal;"

    Set rs = Server.CreateObject("ADODB.Recordset")


    'We need to insert a record into the database
    SQLStmt = "INSERT INTO Postcard (" & _
              "passw, postal, nameto, namefrom, " & _
              "emailfrom, emailto, message, data) " & _
           "VALUES ("

     ' We need a random number for our password, so
     ' use randomize/rnd to make a random number.
     randomize()
     passw = Int((9999-1)*Rnd + 1)

     SQLStmt = SQLStmt & passw & ",'" & session("postal") & _
               "','" & session("nameto") & "','" & _
               session("namefrom") & "','" & _
               session("emailfrom") & "','" & _
               session("emailto") & "','" & _
               session("message") & "','" & session("data") & "')"

     ' Write information to database
     rs.Open SQLStmt, Conn


     ' Now you will see how to use the Free Persits
     ' E-Mail component

     ' First, Create the Mail object
     Set Mail = Server.CreateObject("Persits.MailSender")  

     ' Put the mail server you are using
     Mail.Host = "mail.mailserver.com"

     ' Send the information of the
     ' person that is sending the e-mail
     Mail.From = session("emailfrom")

     ' Who you're sending the email to.
     Mail.FromName = session("namefrom")

     ' Put the email to send to, as well as the name of the person  
     Mail.AddAddress session("emailto"), session("nameto")  

     ' Subject of the email
     Mail.Subject = "Digital PostCard to " & session("nameto")

     ' Print the body of the email
     enviar = "Let me inform you that " & session("namefrom") & _
              Chr(13) & Chr(10) & _
              "have sent you a digital card. To see " & _
              "it follow the link :" & _
              Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
              "http://www.???????.com/view.asp?fromn=out&" & _
              "ident=" & identifier & _
              "&psw=" & passw & " " & Chr(13) & Chr(10) & _
              " your card is available till the day " & _   
              formatDateTime(d,2) & _
              Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
              Chr(13) & Chr(10) & _
              "        Thanks"   

     Mail.Body = enviar

     'Just skip if there are any errors...
     On Error resume Next  

     ' This will send the email
     Mail.Send  


     ' Display an error message if there was an error
     If Err <> 0 Then %>
         <img src="images/error.gif" width="322" height="53"  
               border="0">
     <%
         'Comment out this code if you want to see
         'the error number
         'Response.Write "<br><br>" & "Error found : " & _
                         Err.description & "<br><br>"

         Response.Write "<center><p>SERVER SIDE ERROR, " & _
                        "contact site webmaster.</p></center>"

         goby = 0  
     Else
          Response.Write "<br><br><br><center><p>POSTCARD WAS SENT " & _
                         "NO PROBLEMS...<br>"
     End if
End if

' I think that you have seen that I use the JavaScript history.back
' and go.  I use it so when the user come back he don't
' loose any information already entered into the form.
%>

<center>
    <a href="javascript:history.go('-2')">
        <img src="../images/rebuiltbutton.gif" width="60"  
              height="53" border="0">
    </a>
</center>
</strong></small></font>

</body>
</html>



Get the E-Mail free component:http://www.aspemail.com/

Let me explain how to set it up. Put the component wherever you want, I usually put the components I use
in the directory C:\Inetpub\components\. Then register it (after you put it in the directory you want) by
typing:


regsvr32 AspEmail.dll
from the command line. That's all! Remember, the email code won't work unless you register the component!
If you have any questions, please contact me:http://www.4guysfromrolla.com/webtech/joao.shtml
相关文章 热门文章
  • 用C++ Builder实现电子邮件群发
  • 用Cdonts实现发送Email
  • Jmail的主要参数列表
  • ASP.NET 2.0发送电子邮件全面剖析之二
  • VC++ SMTP协议电子邮件传送剖析
  • 通过sina的smtp验证的Java发送邮件源代码
  • ASP.NET 2.0中发送电子邮件剖析之一
  • 在Asp.Net中使用SmtpMail发送邮件的方法
  • .NET环境下Email的技术介绍
  • ASP.NET 2.0发送电子邮件中存在的问题
  • 用ASP判断Email地址是否有效
  • IIS如何接收ServerXMLHTTP传过来的编码字符?
  • 自由广告区
     
    最新软件下载
  • SharePoint Server 2010 部署文档
  • Exchange 2010 RTM升级至SP1 教程
  • Exchange 2010 OWA下RBAC实现的组功能...
  • Lync Server 2010 Standard Edition 标..
  • Lync Server 2010 Enterprise Edition...
  • Forefront Endpoint Protection 2010 ...
  • Lync Server 2010 Edge 服务器部署文档
  • 《Exchange 2003专家指南》
  • Mastering Hyper-V Deployment
  • Windows Server 2008 R2 Hyper-V
  • Microsoft Lync Server 2010 Unleashed
  • Windows Server 2008 R2 Unleashed
  • 今日邮件技术文章
  • 腾讯,在创新中演绎互联网“进化论”
  • 华科人 张小龙 (中国第二代程序员 QQ...
  • 微软推出新功能 提高Hotmail密码安全性
  • 快压技巧分享:秒传邮件超大附件
  • 不容忽视的邮件营销数据分析过程中的算..
  • 国内手机邮箱的现状与未来发展——访尚..
  • 易观数据:2011Q2中国手机邮箱市场收入..
  • 穿越时空的爱恋 QQ邮箱音视频及贺卡邮件
  • Hotmail新功能:“我的朋友可能被黑了”
  • 入侵邻居网络发骚扰邮件 美国男子被重..
  • 网易邮箱莫子睿:《非你莫属》招聘多过..
  • 中国电信推广189邮箱绿色账单
  • 最新专题
  • 鸟哥的Linux私房菜之Mail服务器
  • Exchange Server 2010技术专题
  • Windows 7 技术专题
  • Sendmail 邮件系统配置
  • 组建Exchange 2003邮件系统
  • Windows Server 2008 专题
  • ORF 反垃圾邮件系统
  • Exchange Server 2007 专题
  • ISA Server 2006 教程专题
  • Windows Vista 技术专题
  • “黑莓”(BlackBerry)专题
  • Apache James 专题
  • 分类导航
    邮件新闻资讯:
    IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮
    电子邮箱 | 反垃圾邮件|邮件客户端|网络安全
    行业数据 | 邮件人物 | 网站公告 | 行业法规
    网络技术:
    邮件原理 | 网络协议 | 网络管理 | 传输介质
    线路接入 | 路由接口 | 邮件存储 | 华为3Com
    CISCO技术 | 网络与服务器硬件
    操作系统:
    Windows 9X | Linux&Uinx | Windows NT
    Windows Vista | FreeBSD | 其它操作系统
    邮件服务器:
    程序与开发 | Exchange | Qmail | Postfix
    Sendmail | MDaemon | Domino | Foxmail
    KerioMail | JavaMail | Winwebmail |James
    Merak&VisNetic | CMailServer | WinMail
    金笛邮件系统 | 其它 |
    反垃圾邮件:
    综述| 客户端反垃圾邮件|服务器端反垃圾邮件
    邮件客户端软件:
    Outlook | Foxmail | DreamMail| KooMail
    The bat | 雷鸟 | Eudora |Becky! |Pegasus
    IncrediMail |其它
    电子邮箱: 个人邮箱 | 企业邮箱 |Gmail
    移动电子邮件:服务器 | 客户端 | 技术前沿
    邮件网络安全:
    软件漏洞 | 安全知识 | 病毒公告 |防火墙
    攻防技术 | 病毒查杀| ISA | 数字签名
    邮件营销:
    Email营销 | 网络营销 | 营销技巧 |营销案例
    邮件人才:招聘 | 职场 | 培训 | 指南 | 职场
    解决方案:
    邮件系统|反垃圾邮件 |安全 |移动电邮 |招标
    产品评测:
    邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端
    广告联系 | 合作联系 | 关于我们 | 联系我们 | 繁體中文
    版权所有:邮件技术资讯网©2003-2010 www.5dmail.net, All Rights Reserved
    www.5Dmail.net Web Team   粤ICP备05009143号