SunQuest
 
           Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old March 6th, 2005, 04:48 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 13 h 47 m 29 sec
Reputation Power: 1441
Post Sending Emails using CDO.Message component

Fully working sub routine to send given email body to given email address:
Code:
 <%
 Const SMTP_SERVER="smtpserver.domain.com"
 
 '--------------------------------------------------------------------
 'SendEmail:
 'Try to send given email using CDO component.
 'Returns empty string in case of success or error message in case of error.
 '--------------------------------------------------------------------
Function SendEmail(strEmailTo, strEmailFrom, strEmailSubject, strEmailBody, arrAttachments)
	'declare variables
	Dim objMessage	'object for sending email
	Dim objConf	'object for configuration of email settings
	Dim x		'loop iterator
	
	'define default return value:
	SendEmail=""
	
	'create objects:
	Set objMessage=Server.CreateObject("CDO.Message")
	Set objConf=Server.CreateObject("CDO.Configuration")
	
	'define settings:
	If Len(SMTP_SERVER)=0 Then
		objConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=1
	Else  
		objConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 'cdoSendUsingPort
	End If
	objConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory")=Server.MapPath("/")
	If Len(SMTP_SERVER)>0 Then
	    objConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")=SMTP_SERVER
	End If
	objConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
	objConf.Fields.Update
	
	'apply settings:
	Set objMessage.Configuration=objConf
	
	'build message details:
	objMessage.To=strEmailTo
	objMessage.From=strEmailFrom
	objMessage.Subject=strEmailSubject
	objMessage.HtmlBody=strEmailBody
	
	If IsArray(arrAttachments) Then
		For x=0 To UBound(arrAttachments)
			objMessage.AddAttachment arrAttachments(x)
		Next
	End If
	
	'catch errors and try to send:
	On Error Resume Next
		objMessage.Send
		If Err.Number<>0 Then
			SendEmail=Err.Description
			Err.Clear
		End If
	On Error Goto 0
	
	'done, clear objects from the memory:
 	Set objMessage=Nothing
 	Set objConf=Nothing
End Function

'usage:
Dim strError
strError = SendEmail("someone@somewhere.com", "test <test@test.com>", "testing without attachments", "hello world", "")
If Len(strError)=0 Then
	Response.Write("success!<br />")
Else  
	Response.Write("failure: " & strError & "<br />")
End If
strError = SendEmail("someone@somewhere.com", "test <test@test.com>", "testing with attachments", "hello world", Array(Server.MapPath("file1.txt"), Server.MapPath("file2.asp")))
If Len(strError)=0 Then
	Response.Write("success!")
Else  
	Response.Write("failure: " & strError & "<br />")
End If
 %>
 

-attached is the same code as text file.
Attached Files
File Type: txt SendMail.asp.txt (2.5 KB, 98 views)

Last edited by Shadow Wizard : April 8th, 2008 at 06:30 AM.

Reply With Quote
  #2  
Old April 14th, 2006, 03:34 AM
matrixtlm matrixtlm is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 119 matrixtlm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 18 h 1 m 15 sec
Reputation Power: 3
Quote:
Originally Posted by Shadow Wizard
Fully working sub routine to send given email body to given email address:
Code:
 <%
 Const SMTP_SERVER="smtpserver.domain.com"
 
 '--------------------------------------------------------------------
 'SendEmail:
 'Try to send given email using CDO component.
 'Returns empty string in case of success or error message in case of error.
 '--------------------------------------------------------------------
 Function SendEmail(strEmailTo, strEmailFrom, strEmailSubject, strEmailBody)
 	'declare variables
 	Dim objMessage	'object for sending email
 	Dim objConf	'object for configuration of email settings
 	
 	'define default return value:
 	SendEmail=""
 	
 	'create objects:
 	Set objMessage=Server.CreateObject("CDO.Message")
 	Set objConf=Server.CreateObject("CDO.Configuration")
 	
 	'define settings:
 	If Len(SMTP_SERVER)=0 Then
 		objConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=1
 	Else  
 	    objConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 'cdoSendUsingPort
 	End If
     objConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory")=Server.MapPath("/")
 	If Len(SMTP_SERVER)>0 Then
 	    objConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")=SMTP_SERVER
 	End If
 	objConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
 	objConf.Fields.Update
 	
 	'apply settings:
 	Set objMessage.Configuration=objConf
 	
 	'build message details:
 	objMessage.To=strEmailTo
 	objMessage.From=strEmailFrom
 	objMessage.Subject=strEmailSubject
 	objMessage.HtmlBody=strEmailBody
 	
 	'catch errors and try to send:
 	On Error Resume Next
 		objMessage.Send
 		If Err.Number<>0 Then
 			SendEmail=Err.Description
 			Err.Clear
 		End If
 	On Error Goto 0
 	
 	'done, clear objects from the memory:
 	Set objMessage=Nothing
 	Set objConf=Nothing
 End Function
 %>
 

-attached is the same code as text file.


How bout adding attachment to it? How to edit the script to include attachment in the email as well ?

Reply With Quote
  #3  
Old April 16th, 2006, 08:34 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 13 h 47 m 29 sec
Reputation Power: 1441
good point, the code has been changed to support attachments now. also, added
usage samples.

Reply With Quote
  #4  
Old December 22nd, 2007, 05:50 AM
solids solids is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 77 solids Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 19 h 23 m 51 sec
Reputation Power: 0
failure: The transport failed to connect to the server.
CDO.Message.1 error '80070002'

The system cannot find the file specified.

/ssp07/butt/email.asp, line 133







iam geting that errer message

Reply With Quote
  #5  
Old December 23rd, 2007, 03:01 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 13 h 47 m 29 sec
Reputation Power: 1441
what is line 133?

Reply With Quote
  #6  
Old December 23rd, 2007, 05:38 AM
solids solids is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 77 solids Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 19 h 23 m 51 sec
Reputation Power: 0
Code:
	If IsArray(arrAttachments) Then
		For x=0 To UBound(arrAttachments)
			objMessage.AddAttachment arrAttachments(x)
		Next
	End If


the bold line is 133...

All i did was copy the hole code and put it in my asp page..do i need to make any changed to it?

Reply With Quote
  #7  
Old December 23rd, 2007, 09:40 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 13 h 47 m 29 sec
Reputation Power: 1441
the files you tried to attach don't exist on your server.
for example if you have this exact code:
Code:
strError = SendEmail("someone@somewhere.com", "test <test@test.com>", "testing with attachments", "hello world", Array(Server.MapPath("file1.txt"), Server.MapPath("file2.asp")))

then you should have file named "file1.txt" and file named "file2.txt" on your server.

this was given as example only, sorry if it's not clear enough in the original post.

Reply With Quote
  #8  
Old December 23rd, 2007, 09:50 AM
solids solids is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 77 solids Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 19 h 23 m 51 sec
Reputation Power: 0
ok quck quston..
do i need a page b4 this page which the user enters there email address in and text area where they put there email in and when they hit send this asp page does the rest?

Reply With Quote
  #9  
Old December 23rd, 2007, 09:55 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,621 Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1Folding Points: 325693 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 4 Days 13 h 47 m 29 sec
Reputation Power: 1441
yes usually web programmers use forms to let visitor type something then
they use this in their code.

Reply With Quote
  #10  
Old December 24th, 2007, 12:13 AM
Full Moon Full Moon is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 57 Full Moon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 41 m 33 sec
Reputation Power: 2
hi, i used your code but without the attachment code, but i were wondering what should i put here
""test <test@test.com>"

Reply With Quote
  #11  
Old December 24th, 2007, 02:34 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 10,179 micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)micky User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 3 Months 3 Weeks 1 Day 16 h 36 m 26 sec
Reputation Power: 1427
Quote:
Originally Posted by Full Moon
hi, i used your code but without the attachment code, but i were wondering what should i put here
""test <test@test.com>"
read the code for function SendEmail
its the email address of the sender of mail with the name(if u want)
__________________
Laziness is my religion and Sunday is my God

Get the Mantra!

Reply With Quote
  #12  
Old December 24th, 2007, 04:08 AM
Full Moon Full Moon is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 57 Full Moon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 41 m 33 sec
Reputation Power: 2
thanks, but it now it giving me the following error:
failure: The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for "my email address"

Reply With Quote