vb Send an email

Public Sub SendEmail(strFrom, strTo, strSubject, strBody) 'move to /slickcms/messaging.asp?
	'sends an email using CDO.Message
	Dim cdoMessage
	Dim cdoConfig

	strFrom = ValidateEmail(strFrom)
	strTo = ValidateEmail(strTo)
	
	If Application("Debug") = 1 Then
		Response.Write(strFrom & "<br />" & strTo)
	End If
	
	If (Len(strFrom) = 0) Or (Len(strTo) = 0) Then
		Session("EmailSent") = false
		Exit Sub
	End If

	Set cdoConfig = CreateObject("CDO.Configuration")  
	Set cdoMessage = Server.CreateObject("CDO.Message")

	With cdoConfig.Fields  
		.Item(cdoSendUsingMethod) = 2
		.Item(cdoSMTPServer) = Application("Mail_SMTP")
		.Item(cdoSMTPServerPort) = Application("Mail_Port")
		
		'use SMTP authentication if details provided
		If Application("Mail_User") <> "" And Application("Mail_Password") <> "" Then
			.Item(cdoSMTPAuthenticate) = 1
			.Item(cdoSendUsername) = Application("Mail_User")
			.Item(cdoSendPassword) = Application("Mail_Password")
		Else
			.Item(cdoSMTPAuthenticate) = 0
		End If

		.Update  
	End With 
	
	With cdoMessage 
		Set .Configuration = cdoConfig 
		.From = strFrom
		.To = strTo
		.Subject = strSubject
		
		If Application("Mail_Type") = "PLAIN" Then
			.TextBody = strBody
		Else
			.HTMLBody = strBody
		End If
		
		.Send 
	End With

	Set cdoMessage = Nothing
	Set cdoConfig = Nothing 
	
	If err.number <> 0 Then
		Session("EmailSent") = false
	Else
		Session("EmailSent") = true
	End If
End Sub
Send an email - as used within slickcms

Updated: Saturday 9th October 2010, 10:48pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.