Sending e-mail using ASP & MAPI

Posted on 2005-04-07
Last Modified: 2008-03-17
I borrowed from code found here:

I am trying to understand how to send an e-mail using ASP & MAPI.

LocalServer = "MyServerName"
LocalMailBox = "MyMailbox"
toemail = ""
ActMsgTo = "dontunderstandthisfield"
subjecttext = "Test"
bodytext = "This is a test"

Dim objSession As Object ' MAPI.Session
    Dim objOutbox As Object ' MAPI.Folder
    Dim objNewMessage As Object ' MAPI.Message
    Dim objRecipients As Object ' MAPI.Recipients
    Dim objOneRecip As Object ' MAPI.Recipient

            Set objSession = CreateObject("MAPI.Session")
            objSession.Logon profileinfo:=LocalServer & vbLf & LocalMailBox, nomail:=True
            Set objOutbox = objSession.Outbox
            Set objNewMessage = objOutbox.Messages.Add
            Set objRecipients = objNewMessage.Recipients
            Set objOneRecip = objRecipients.Add
            With objOneRecip
                .Name = toemail
                .Type = ActMsgTo
                .Resolve ' Get MAPI to determine complete E-mail address.
            End With
            With objNewMessage
                .Subject = subjecttext
                .Text = bodytext
            End With

I don't understand the purpose of: ActMsgTo

I tried just using my username.

When I open the page I get: HTTP 500 - Internal server error

What do I need to do to make this work?
Question by:lpenrod
    LVL 3

    Author Comment

    LVL 15

    Accepted Solution

    First of all, turn off "friendly error messages" so you get better error messages than "500 internal server error".

    Second, in VBScript you don't dim as variable as an object type. So this:

    Dim objNewMessage As Object

    will error. It should simply be:

    Dim objNewMessage

    Thirdly, all objects that come from the "MAPI.<class name>" namespace come from the CDO 1.2 .dll. Your code will only work if this .dll is installed on your system. This is no longer part of a standard installation of any version of Windows or Office. The easiest way to install this component is to install Outlook with a custom installation configuration and make sure the "Collaboration Data Objects" options is selected.

    And to answer your question: the Type property of the recipient object specifies whether the recipient is a 'To', 'CC' or 'BCC' recipient. The values you set are 1 (for To), 2 (for CC) or 3 (for BCC).

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
    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…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    729 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

    18 Experts available now in Live!

    Get 1:1 Help Now