Sending e-mail using ASP & MAPI

I borrowed from code found here: http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_11046024.html

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

<%
LocalServer = "MyServerName"
LocalMailBox = "MyMailbox"
toemail = "myemail@mydomain.com"
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
                .Send
            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?
LVL 3
lpenrodAsked:
Who is Participating?
 
deighcCommented:
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).
0
 
lpenrodAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.