Using JMail with ASP pages:
JMail by Dimac allows programmers to easily send e-mail with just a few lines of ASP code. Simply set a few JMail properties and send the message.
The following ASP example illustrates the most commonly-used features of the JMail program which is already installed on your Windows NT hosting account:
- First, initialize the JMail program...
- Set JMail = Server.CreateObject("JMail.SMTPMail")
- Next, define your SMTP server & port address...
(note that you just need to use the following line:
JMail.ServerAddress = "127.0.0.1:25"
(This just means, use the local server on port #25 - don't change this setting.)
- The JMail Sender property is what you set to let your recipient know who the e-mail is from, for example...
JMail.Sender = "mailbot@yourdomain.com"
- The Subject property allows you to fill in the subject of the e-mail message you're sending...
JMail.Subject = "Info you requested..."
- To add recipients to the e-mail message, you use the AddRecipient method. Note that it does not require the use of an = sign!
JMail.AddRecipient "user@somehost.com"
You can keep adding recipients until you're done...
JMail.AddRecipient "joe@blow.com"
JMail.AddRecipient "shag@austinbaby.com"
- You can also add recipients to what would normally be the CC: and BCC: fields of your e-mail, as follows (respectively)...
JMail.AddRecipientCC "boss@job.com"
JMail.AddRecipientBCC "secret@squirrel.com"
- If you want to make the To: address more personal, you can use the AddRecipientEx method to add not only the person's e-mail address, but their name, too...
JMail.AddRecipientEx "lame@address.com", "Sparky O'Malley"
- The body of your message can be set in a number of ways. To set the body explicitly, you can just do something like this...
JMail.Body = "Thanks for signing up!"
Or you might need to add text later after a generic greeting, in which case you'd append text to the body like this...
JMail.Body = JMail.Body & "Have a nice day!"
- You can also append text with the AppendText method...again, note the lack of an = sign here because you're using a method, not setting a property...
JMail.AppendText "Have a nice day!"
If you have some text stored in a file, you can also use the contents of that file to set the body of the message, as follows...
JMail.AppendBodyFromFile "c:\webserver\yourdomain\htdocs\mytext.txt"
- If your message is really important, you may want to set the message priority with the Priority property. When setting this property, remember that 1 is highest priority (urgent) and 5 is lowest priority...
JMail.Priority = 1
- You can even add attachments to your message. As with the AddRecipient method, this does not use = signs and can be called as many times as you have attachments...
JMail.AddAttachment "c:\webserver\yourdomain\htdocs\pix\myphoto.jpg"
JMail.AddAttachment "c:\webserver\yourdomain\htdocs\faq\faq1.txt"
- Once you've set everything up, it's just a matter of sending the message...
JMail.Execute
Example Form
Here is a very simple example, without all the comments, that takes data from a form and sends a simple message to the user: The code must begin with <% and end with %>
<%
Set JMail = Server.CreateObject("JMail.SMTPMail")
JMail.ServerAddress = "127.0.0.1:25"
JMail.Sender = "mailbot@yourdomain.com"
JMail.Subject = "Sign-up acknowledgement..."
JMail.AddRecipientEx Request.Form("EMailAddress"),
Request.Form("UserName") JMail.Body = "Thanks for signing up for our new
online service!" JMail.Execute
%>