Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send an email using vbs

Status
Not open for further replies.

MrDontKnowNothing

Programmer
Jun 26, 2003
94
DE
hi folks,

i'm working on an asp-website using vbs and i need to send a mail. any hints how to do that?

cheers

alex
 
There are other ways to send email using asp.
Here is a VBscript I use to send email with a file attchment in outlook using MAPI.
Enjoy Bob

Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
ToAddress = "email@email.com"
MessageSubject = "This is the message subject"
MessageBody = "this is the message body"
MessageAttachment = "c:\folder\folder\file.ext"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send
 
here is a script that I use, its not mine and I did not write it...this is just to give you some help


On Error Resume Next
Dim WSHShell, objOutlook, objMsg, strTitle
Dim strSendTo, strSubj,strBody
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objOutlook = Wscript.CreateObject("Outlook.Application")
strTitle="Send Outlook Email"

' Set a reference to the MailItem object
Set objMsg = objOutlook.CreateItem(0)
if err.number<>0 then
wscript.echo &quot;(&quot;&err.number&&quot;) &quot;& err.description
wscript.echo &quot;Error creating Outlook object.&quot;
wscript.quit(1)
end if

' Get an address from the user
strSendTo=objMsg.Recipients.Add(InputBox(&quot;Enter email address of recipient or recipients separated by commas.&quot;,strTitle))
if strSendTo=&quot;&quot; then
wscript.echo &quot;No addresses specified. Cancelling remaining script processing.&quot;
Set objOutlook = Nothing
Set objMsg = Nothing
Set recMessage = Nothing
wscript.quit(1)
end if

' Add subject and body text
objMsg.Subject = InputBox(&quot;What is the subject of your message?&quot;,strTitle)
if objMsg.Subject=&quot;&quot; then
x=MsgBox(&quot;No subject specified or you clicked Cancelled. Do you want to quit?&quot;,4+32,strTitle)
if x=6 then
Set objOutlook = Nothing
Set objMsg = Nothing
Set recMessage = Nothing
wscript.quit
end if
end if

objMsg.Body = InputBox(&quot;What is your message?&quot;,strTitle)
if objMsg.Body=&quot;&quot; then
x=MsgBox(&quot;No body specified or you clicked Cancelled. Do you want to quit?&quot;,4+32,strTitle)
if x=6 then
Set objOutlook = Nothing
Set objMsg = Nothing
Set recMessage = Nothing
wscript.quit
end if
end if

'Review the message
ReviewItem=&quot;To: &quot; & strSendTo & VBCRLF & &quot;Subject: &quot; & objMsg.Subject & VBCRLF & objMsg.Body
y=MsgBox(ReviewItem & VBCRLF & VBCRLF &&quot;Do you want to send this message?&quot;,4+32,strTitle)

if y=7 then
Set objOutlook = Nothing
Set objMsg = Nothing
Set recMessage = Nothing
wscript.quit
end if

' Send the mail
objMsg.Send
if err.number<>0 then
wscript.echo &quot;Error sending mail message.&quot;
wscript.echo &quot;(&quot;&err.number&&quot;) &quot;& err.description
wscript.quit(1)
else
wscript.echo &quot;Message sent to &quot; & strSendTo
end if

' Close object references
Set objOutlook = Nothing
Set objMsg = Nothing
Set recMessage = Nothing

Wscript.Quit(0)
 
While this will work, you may be better off looking into CDONTS, CDO, or some third party email component.

&quot;Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when run in this environment.&quot;


Some examples of using CDONTS, CDO, and Outlook are at:


Servers don't normally have Office installed anyway. If you choose to do this see the tips on Configuring Office to Run Server-Side in the Microsoft article above.

My own experience has been that while my ASP pages were hit only lightly everything worked. As soon as volume got up to a hit every couple seconds though (site was in production) users started getting lots of errors. CDO seems to be working great.
 
Plenty more info about this:

I also recommend using CDO or another mail component such as JMail (which is very likely to be already installed by your ASP host!). Good luck

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top