VB icon

Universal Email Interface

Email
Submitted on: 1/6/2015 2:43:00 AM
By: Lewis E. Moten III (from psc cd)  
Level: Intermediate
User Rating: By 4 Users
Compatibility: ASP (Active Server Pages)
Views: 1372
 
     Lays down a universal interface to sending email. Easier to port to other servers that use different COM objects to send email. Even exposes a list of ProgID's that are installed on the server. (This is the beginnig. But I am sure you can see where the benefit of this code is going)
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Universal Email Interface
' Description:Lays down a universal interface to sending email. Easier to port to other servers that use different COM objects to send email. Even exposes a list of ProgID's that are installed on the server. (This is the beginnig. But I am sure you can see where the benefit of this code is going)
' By: Lewis E. Moten III (from psc cd)
'**************************************

<%
Class clsEmail
	
	Public SenderName
	Public SenderAddress
	Public RecipientName
	Public RecipientAddress
	Public Subject
	Public Message
	Public Host
	Public ProgID
	Public LogonUsername
	Public LogonPassword
	
	Private Sub Class_Initialize()
		' Setup default values
		SenderAddress	= Application.Value("Settings-Email-Address")
		SenderName		= Application.Value("Settings-Email-Name")
		Host			= Application.Value("Settings-Email-Server")
		ProgID			= Application.Value("Settings-Email-ProgID")
	End Sub
	
	Public Property Get Installed()
		Dim llngIndex
		Dim llngMaxIndex
		Dim lstrProgIDs
		Dim lstrProgIDAry
		Dim lstrPairAry
		Dim lstrInstalled
		Dim lobjTest
		
		On Error Resume Next
		
		lstrProgIDs = _
			"CDONTS.NewMail:Collaborative Data Objects for NT;" & _
			"SMTPsvg.Mailer:Server Objects - ASPMail/ASPQMail"
		'	"POPsvb.Mailer:Server Objects - ASP Pop3;" & _
		'	"SoftArtisans.SMTPMail:Software Artisans - SMTP Mail;" & _
		'	"Jmail.smtpmail:w3 JMail;" & _
		'	"Persists.MailSender:Persists - ASPEmail;" & _
		'	"dkQmail.Qmail:dkQmail;" & _
		'	"Geocel.Mailer:GeoCel;" & _
		'	"iismail.iismail.1:IISMail;" & _
		'	"SmtpMail.SmtpMail.1:SMTP;" & _
		'	"ocxQmail.ocxQmailCtrl.1:OCXQMail;" & _
		'	"Dundas.Mailer:Dundas - ASPMailer;" & _
		'	"EasyMail.SMTP.5:Quicksoft - EasyMail"
		lstrProgIDAry = Split(lstrProgIDs, ";")
		
		llngMaxIndex = UBound(lstrProgIDAry)
		
		For llngIndex = 0 To llngMaxIndex
			lstrPairAry = Split(lstrProgIDAry(llngIndex), ":")
			Set lobjTest = Server.CreateObject(lstrPairAry(0))
			If Err Then
				Err.Clear
			Else
				lstrInstalled = lstrInstalled & lstrProgIDAry(llngIndex) & ";"
			End If
		Next
		
		If Right(lstrInstalled, 1) = ";" Then
			lstrInstalled = Left(lstrInstalled, Len(lstrInstalled) - 1)
		End If
		
		Installed = lstrInstalled
		
	End Property	
	Public Sub Send()
		
		If ProgID = "" Then 
			Call Err.Raise(vbObjectError + 1, "clsEmail.asp", "The ProgID has not been defined.")
			Exit Sub
		End If
		
		Dim lobjMailer
		
		Set lobjMailer = Server.CreateObject(ProgID)
		
		If SenderName = "" Then SenderName = SenderAddress
		If RecipientName = "" Then RecipientName = RecipientAddress
		
		Select Case LCase(ProgID)
			Case "cdonts.newmail"
				lobjMailer.From		= SenderName & "<" & SenderAddress & ">"
				lobjMailer.To		= RecipientName & "<" & RecipientAddress & ">"
				lobjMailer.Subject	= Subject
				lobjMailer.Body		= Message
				lobjMailer.Send()
			Case "smtpsvg.mailer"
				Call lobjMailer.AddRecipient(RecipientName, RecipientAddress)
				lobjMailer.RemoteHost	= Host
				lobjMailer.FromAddress	= SenderAddress
				lobjMailer.FromName		= SenderName
				lobjMailer.Subject		= Subject
				lobjMailer.BodyText		= Message
				lobjMailer.SendMail
			Case Else
				Call Err.Raise(vbObjectError + 2, "clsEmail.asp", "The ProgID """ & ProgID & """ is not registered.")
		End Select
		
		Set lobjMailer = Nothing
	End Sub
End Class
' ------------------------------------------------------------------------------
%>


Other 63 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.