Important alert: (current site time 7/15/2013 11:01:53 PM EDT)
 

VB icon

Email code as a Function

Email
Submitted on: 5/9/2006 10:00:46 PM
By: Nate T Norris  
Level: Beginner
User Rating: By 1 Users
Compatibility: ASP (Active Server Pages), HTML, VbScript (browser/client side)
Views: 8037
author picture
(About the author)
 
     Create a Function for your Email Send form for those repeditive Email calls
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
' for :Email code as a Function
'**************************************
Copyright Monday, October 17, 2005 - Nate T Norris.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Email code as a Function
' Description:Create a Function for your Email Send form for those repeditive Email calls
' By: Nate T Norris 
'
' Inputs:strMailFrom - Email listed as FROM in email for ReplyTO's
strFromName - Name listed as FROM in email 
strAddAddress - The email address of the recipient
strSubject - Subject line
strBody - Body text
'
' Returns:If no errors, it return TRUE to a variable assignment. No real result other that the email form script being executed
'
' Assumes:This script assumes CDO email code, but can be gutted to template any email code.
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=9377&lngWId=4'for details.'**************************************

'**********************************************
' Description:	CDO Email Form Function
'
' Author:	Nate Norris		
'
' Created:	Monday, October 17, 2005
'
' Inputs:	form elements
' Outputs:	error report - if any
'*********************************************
Function xEmailForm_CDO(strMailFrom,strFromName,strAddAddress,strSubject,strBody)
'##############################################
'Email the contact information to PMA
		'************************************
		if strMailFrom <> "" then
			'
		else 
			strMailFrom = "EMAIL@EMAIL.com"
		End If
	
		'Generate email objects
		Set objEMail = Server.CreateObject("CDO.Message")
		Set objConfig = Server.CreateObject("CDO.Configuration")
		Set Confi = objConfig.Fields
		Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
		Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
		Confi.Update
		Set objEMail.Configuration = objConfig
		objEMail.From = strFromName & "<" & strMailFrom & ">"
		objEMail.Subject = strSubject
		objEMail.TextBody = strBody
		objEMail.HTMLBody = "<p>" & strBody
		
		objEMail.To = strAddAddress 'str can be formatted for multiple i.e. "a@b.com; b@c.com"
			
		
		' REF: http://www.w3schools.com/asp/asp_send_email.asp
		' REF: http://www.paulsadowski.com/WSH/cdo.htm
		'*****************************
'#############################################
	On Error Resume Next
	objEMail.Send	
	'handle the errors
	If Err <> 0 Then
	strEmailErrorHolder = "Error encountered: " & Err.Description
		If instr(Err.Description, "5.5.4 Invalid Address") then 
			strEmailErrorHolder = strEmailErrorHolder & " - [" & xemailx & "] <BR>" 
		End IF
	Else 
		strEmailErrorHolder = "no error"
	End If 
	'destroy the obj
	Set objEMail = Nothing
	'set the result
	xEmailForm_CDO = strEmailErrorHolder
END Function
''PAGE CODE TO CALL AND USE THE FUNCTION
'strMailFrom = "EMAIL@EMAIL.com"
'strFromName = "NAME"
'strAddAddress = "EMAIL@EMAIL.com" 'single address only
'strSubject = "SUBJECT"
'strBody = "<h1>Hi</h1>" 'HTML OK
'
'strEmailError = xEmailForm_CDO(strMailFrom,strFromName,strAddAddress,strSubject,strBody)


Other 5 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 Beginner 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

4/3/2009 1:32:21 AMEngr. Asif JAmali

I feel proud to be the member of this site. I want to get direct code access from this site

(If this comment was disrespectful, please report it.)

 

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.