Solved

Send Email  with VBScript

Posted on 1998-12-30
3
473 Views
Last Modified: 2008-02-20
I need to send a email with VBScript on a system with NT 4.0, IIServer 4.0 and Exchange 5.5 and ASPMail.

Email is into Intraweb, users of Exchange 5.5.

What's Code i need to execute?.
0
Comment
Question by:javi2
3 Comments
 
LVL 3

Expert Comment

by:vmano
ID: 1453326
here is an MSDN article Q176914. URL is
http://support.microsoft.com/support/kb/articles/q176/9/14.asp?FR=0 

let me know if that helps
vmano
0
 
LVL 1

Accepted Solution

by:
wdavidsmith earned 50 total points
ID: 1453327
Here's the simple, easy solution I recently employed...

1.) Include the MAPI32 ActiveX control tags in your page. Both tags reference the same OCX. The message control AND the session control are both embedded into this OCX file. Make sure the codebase path is correct for your site. Also make sure you have the OCX file in the referenced folder.

NOTE:The MSMAPI32.ocx control is a licensed control. You'll need to include an LPK tag to license the control. The LPK file can be created with the LPK License Tool.

<OBJECT codebase="Controls/MSMAPI32.ocx"
 ID="ctlMessage" WIDTH=39 HEIGHT=39
 CLASSID="CLSID:20C62CAB-15DA-101B-B9A8-444553540000">
    <PARAM NAME="_ExtentX" VALUE="1005">
    <PARAM NAME="_ExtentY" VALUE="1005">
    <PARAM NAME="_Version" VALUE="327680">
    <PARAM NAME="AddressEditFieldCount" VALUE="1">
    <PARAM NAME="AddressModifiable" VALUE="0">
    <PARAM NAME="AddressResolveUI" VALUE="0">
    <PARAM NAME="FetchSorted" VALUE="0">
    <PARAM NAME="FetchUnreadOnly" VALUE="0">
</OBJECT>

<OBJECT codebase="Controls/MSMAPI32.ocx"
 ID="ctlSession" WIDTH=39 HEIGHT=39
 CLASSID="CLSID:20C62CA0-15DA-101B-B9A8-444553540000">
    <PARAM NAME="_ExtentX" VALUE="1005">
    <PARAM NAME="_ExtentY" VALUE="1005">
    <PARAM NAME="_Version" VALUE="327680">
    <PARAM NAME="DownloadMail" VALUE="0">
    <PARAM NAME="LogonUI" VALUE="0">
    <PARAM NAME="NewSession" VALUE="0">
</OBJECT>

2.) Copy and paste the following into your page
<SCRIPT LANGUAGE="VBScript">
Sub SendMessage(strAddress, strSubject, strMessage)

   ' If the address, subject and message variables are in place
   If strAddress = "" Or strSubject = "" Or strMessage = "" Then
      ' Either the address, subject and/or message variables were empty
      MsgBox "Error Constructing Email Message"
      Exit Sub
   End If

   ' If a messaging system session does NOT exist
   If ((ctlMessage.SessionID = 0) Or IsNull(ctlMessage.SessionID)) Then
      ' Log the user on to the messaging system
      ctlSession.SignOn
      ' Get the messaging system session ID
      ctlMessage.SessionID = ctlSession.SessionID
   End If

   ' Compose the email from the variables
   ctlMessage.Compose
   ctlMessage.AddressResolveUI = 0
   ctlMessage.RecipAddress = varAddress
   ctlMessage.MsgSubject = varSubject
   ctlMessage.MsgNoteText = varMessage
   ctlMessage.ResolveName
     
   ' Send the email without user interaction
   ctlMessage.Send 0
     
   ' If an error was encountered
   If Err.Number > 0 Then
      ' Display an error message (email application probably not open)
      MsgBox "ERROR: " & CStr(Err.Number) & Chr(13) & _
                     "Unable to Send Email" & Chr(13) & Chr(13) & _
                     "Make sure you Email Program" & Chr(13) & _
                     "is Open and working correctly"
      ' Clear the error
      Err.Clear
      Exit Sub
   Else
      ' Display a success message
      MsgBox "Email Sent"
   End If

End Sub
</SCRIPT>

NOTE: The users will need to have their email application (i.e. Exchange) open for the control to access it.

3.) Call the SendMessage sub with the email address, subject, and message strings. For example:
SendMessage("joe@hishouse.net", "Kewl Email!", "Hey Joe...")

I have literally hunderds of users who use this on a daily basis and it works great. I hope this helps...


0
 

Author Comment

by:javi2
ID: 1453328
Very Thanxs, i will try it soon.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 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

15 Experts available now in Live!

Get 1:1 Help Now