w3JMail Examples

Examples 4.5

PGP encryption

Using w3 JMail with PGP is very easy once you have installed and set up PGP on your webserver.This example shows just how easy it is, just by setting a few properties. The email will be encrypted using a PGP key.You can get a free version of PGP at http://www.pgpi.com/ . Read the instructions in the manual on how to make PGP work with w3 JMail, it's not hard, but there are some things you need to do before it works.If you have trouble making PGP work, you should direct your questions to where you got PGP. We do NOT give support on PGP itself.

   JMailPGP.asp


<%@LANGUAGE="VBSCRIPT" %>
<HTML>
<BODY>
<%
' PGP encryption
' The message is set up as usual...

set msg = Server.CreateObject( "JMail.Message" )

msg.From = "myEmail@mydomain.com"
msg.Subject = "For your eyes only"
msg.Body = "Top secret stuff for you."

' Set logging to true to ease any potential debugging
' And set silent to true as we wish to handle our errors ourself

msg.Logging = true
msg.silent = true

' An encryption key can be set as the third parameter to AddRecipient.
' This can be a comma separated string containing email addresses and
' hexadecimal key id's if more than one key are going to be used.
' The third parameter is optional and will default to the same value
' as the recipients email address, which in most cases are quite sufficient.

' msg.AddRecipient("myFriend@hisdomain.com", "A Name", "anEmail@mydomain.com, 0xFD43CD12, anotherEmail@mydomain.com" )


msg.AddRecipient "myRecipient@hisdomain.com", "A Name"

' With PGPEncrypt set to true the email will be encrypted upon Send()
msg.PGPEncrypt = true

' To capture any errors which might occur, we wrap the call in an IF statement
if not msg.Send( "mail.myDomain.net" ) then
    Response.write "<pre>" & msg.log & "</pre>"
else
    Response.write "Message sent succesfully and encrypted!"
end if
%>
</BODY>
</HTML>