AspEmail Sample Code

AspEmail is an active server component for sending e-mail messages using an external SMTP server in an ASP or VB environment. AspEmail supports multiple recipients, multiple file attachments, HTML format, embedded images and sounds, non-US ASCII character sets, secure mail, and high-performance message queuing.

The following code sample demonstrates a simple email-sending form.


' change to address of your own SMTP server   
strHost = ""    
If Request("Send") <> "" Then   
   Set Mail = Server.CreateObject("Persits.MailSender")   
   ' enter valid SMTP host   
   Mail.Host = strHost    
   Mail.Username = ”" 
   Mail.Password = “password”  
   Mail.From = Request("From") ' From address   
   Mail.FromName = Request("FromName") ' optional   
   Mail.AddAddress Request("To")    
   ' message subject   
   Mail.Subject = Request("Subject")   
   ' message body   
   Mail.Body = Request("Body")   
   strErr = ""  
   bSuccess = False  
   On Error Resume Next ' catch errors   
   Mail.Send ' send message   
   If Err <> 0 Then ' error occurred   
      strErr = Err.Description   
      bSuccess = True  
   End If   
End If   
<% If strErr <> "" Then %>  
<h3>Error occurred: <% = strErr %>  
<% End If %>  
<% If bSuccess Then %>  
Success! Message sent to <% = Request("To") %>.   
<% End If %>  
<FORM METHOD="POST" ACTION="Simple.asp">   
   <TD>Host (change as necessary in script):</TD>  
   <TD><B><% = strHost %></B></TD>  
   <TD>From (enter sender's address):</TD>  
   <TD><INPUT TYPE="TEXT" NAME="From"></TD>  
   <TD>FromName (optional, enter sender's name):</TD>  
   <TD><INPUT TYPE="TEXT" NAME="FromName"></TD>  
   <TD>To: (enter one recipient's address):</TD>  
   <TD><INPUT TYPE="TEXT" NAME="Subject"></TD>  
   <TD COLSPAN=2><INPUT TYPE="SUBMIT" NAME="Send" VALUE="Send Message">