Solved

Sending Mail Script

Posted on 2001-08-09
9
335 Views
Last Modified: 2012-05-04
I am using the folloiwng script to send results from an email form. What I would like to do is:

 - have the email sent to more then one address
 - have the email sent to a third address using the CC email field

<%

Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = "relay.mysite.com"
Mailer.FromAddress = Request.Form("FromAddress")
Mailer.AddRecipient"Info","info@mysite.com"
Mailer.Subject    = Request.Form("Subject")
strMsgHeader = "Form Information Follows: " & vbCrLf
for i = 1 to Request.Form.Count
  strMsgInfo = strMsgInfo & Request.Form.Key(i) & " - " &  Request.Form.Item(i) & vbCrLf
next
strMsgFooter = vbCrLf & "End of form information"
Mailer.BodyText = strMsgHeader & strMsgInfo & strMsgFooter


if Mailer.SendMail then
Response.Redirect("thankyou.asp")

else
Response.Redirect("error.asp")

end if
%>
0
Comment
Question by:ASCAN
9 Comments
 
LVL 3

Expert Comment

by:CyberSoft
ID: 6368016
ASCAN,

Is there any reason why you've opted to use a third party mailer instead of using built in CDO in IIS because CDO supports the multiple email addresses in the TO and CC fields

See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_denali_newmail_object_cdonts_library_.asp

CyberSoft

PS: Respond here if you want some example code using CDO.
0
 
LVL 7

Accepted Solution

by:
John844 earned 100 total points
ID: 6368337
to add multiple recipients I believe that you can just repeat the next line changing the name and email for each new person.
Mailer.AddRecipient"Info","info@mysite.com"

to add the cc recipient, there should be a method similar to the one above, maybe AddCCRecipient.  I don't have that component for reference currently.

John
0
 
LVL 7

Expert Comment

by:John844
ID: 6368359
to add a CC recipient just add a line like

Mailer.AddCC "somename", "someemail.email.com"
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6368593
John844 is correct.

hongjun
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 7

Expert Comment

by:John844
ID: 6368612
thanks for the confirmation hongjun
John
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6368724
For me I am not sure about the component used but for most of the components in the market I know, the algorithm is like that. So I presume that should also be like this. Perhaps, your user manual will tell you more.

hongjun
0
 
LVL 1

Expert Comment

by:bahu_m
ID: 6370306
To send email to multiple users you have to keep adding the users using AddRecipient method. For CC use AddCC method. Check the following code:


Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = "relay.mysite.com"
Mailer.FromAddress = Request.Form("FromAddress")

Mailer.AddRecipient "Info","info@mysite.com"
Mailer.AddRecipient "Info1","info1@mysite.com"
Mailer.AddRecipient "Info2","info2@mysite.com"
Mailer.AddCC "ccname", "ccname@mysite.com"

Mailer.Subject    = Request.Form("Subject")
strMsgHeader = "Form Information Follows: " & vbCrLf
for i = 1 to Request.Form.Count
     strMsgInfo = strMsgInfo & Request.Form.Key(i) & " - " &  Request.Form.Item(i) & vbCrLf
next
strMsgFooter = vbCrLf & "End of form information"
Mailer.BodyText = strMsgHeader & strMsgInfo & strMsgFooter
if Mailer.SendMail then
     Response.Redirect("thankyou.asp")
else
     Response.Redirect("error.asp")
end if
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6370720
bahu_m, that's what John had commented.

hongjun
0
 

Expert Comment

by:pinkstonm
ID: 13212889
Are these statements for CDO?

Mailer.AddRecipient "Info","info@mysite.com"
Mailer.AddRecipient "Info1","info1@mysite.com"
Mailer.AddRecipient "Info2","info2@mysite.com"
Mailer.AddCC "ccname", "ccname@mysite.com"
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now