Solved

Send Email  with VBScript

Posted on 1998-12-30
3
493 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

821 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