Skip to main content

[archive] Emailing with MSMapi and Outlook

  • October 1, 2006
  • 4 replies
  • 0 views

[Migrated content. Thread originally posted on 22 September 2006]

I have a program (I believe it is a sample on one of the forum threads) that I am using to send emails with attachments through MSMAPI. This program works great with Outlook Express. However, when attempting to use the program with Outlook, the emails are placed in the Outbox, when they are eventually sent, they are immediately returned as undeliverable. When I look at the email in sent items, there is no "from" name/address. I have tried to log in as the user name/password and this does not help. Outlook is being used without Exchange Server. I have tried researching this on Microsoft's website, but I basically don't understand how MAPI might differ with and without Exchange Server where Outlook is concerned. Any suggestions?

Here is my code:

CREATE MAPISESSION OF MSMAPI
LICENSE-KEY "mggthkgogggvmkhinjggnvm"
HANDLE IN MAPISession.
CREATE MAPIMESSAGES OF MSMAPI
LICENSE-KEY"nnmnmninigthkgogggvmkhinjggnvm"
HANDLE IN MAPIMessage.
MODIFY MAPISession DOWNLOADMAIL 0.
MODIFY MAPISession USERNAME= "support@drcanswers.com".
MODIFY MAPISession PASSWORD = "support".

MODIFY MAPISession SIGNON().
INQUIRE MAPISession SESSIONID Session_ID.
MODIFY MAPIMessage SESSIONID = Session_ID.
MODIFY MAPIMessage COMPOSE().
MODIFY MAPIMessage MSGSUBJECT = EMAIL-SUBJECT.
MODIFY MAPIMessage MSGNOTETEXT = EMAIL-MESSAGE.
MOVE 0 TO INDX.
PERFORM VARYING PTR FROM 1 BY 1 UNTIL PTR > 59
IF ATTACHMENT-FILE(PTR) NOT = SPACES
MODIFY MAPIMessage
ATTACHMENTINDEX = INDX
ATTACHMENTPOSITION = INDX
ATTACHMENTPATHNAME = ATTACHMENT-FILE(PTR)
ADD 1 TO INDX
END-IF
END-PERFORM.
MODIFY MAPIMessage RECIPDISPLAYNAME = RECIPIENT-ADDRESS.
MODIFY MAPIMessage RECIPADDRESS = RECIPIENT-ADDRESS.

MODIFY MAPIMessage @SEND(0).
MODIFY MAPISession SIGNOFF().
DESTROY MAPIMessage.
DESTROY MAPISession.

4 replies

[Migrated content. Thread originally posted on 22 September 2006]

I have a program (I believe it is a sample on one of the forum threads) that I am using to send emails with attachments through MSMAPI. This program works great with Outlook Express. However, when attempting to use the program with Outlook, the emails are placed in the Outbox, when they are eventually sent, they are immediately returned as undeliverable. When I look at the email in sent items, there is no "from" name/address. I have tried to log in as the user name/password and this does not help. Outlook is being used without Exchange Server. I have tried researching this on Microsoft's website, but I basically don't understand how MAPI might differ with and without Exchange Server where Outlook is concerned. Any suggestions?

Here is my code:

CREATE MAPISESSION OF MSMAPI
LICENSE-KEY "mggthkgogggvmkhinjggnvm"
HANDLE IN MAPISession.
CREATE MAPIMESSAGES OF MSMAPI
LICENSE-KEY"nnmnmninigthkgogggvmkhinjggnvm"
HANDLE IN MAPIMessage.
MODIFY MAPISession DOWNLOADMAIL 0.
MODIFY MAPISession USERNAME= "support@drcanswers.com".
MODIFY MAPISession PASSWORD = "support".

MODIFY MAPISession SIGNON().
INQUIRE MAPISession SESSIONID Session_ID.
MODIFY MAPIMessage SESSIONID = Session_ID.
MODIFY MAPIMessage COMPOSE().
MODIFY MAPIMessage MSGSUBJECT = EMAIL-SUBJECT.
MODIFY MAPIMessage MSGNOTETEXT = EMAIL-MESSAGE.
MOVE 0 TO INDX.
PERFORM VARYING PTR FROM 1 BY 1 UNTIL PTR > 59
IF ATTACHMENT-FILE(PTR) NOT = SPACES
MODIFY MAPIMessage
ATTACHMENTINDEX = INDX
ATTACHMENTPOSITION = INDX
ATTACHMENTPATHNAME = ATTACHMENT-FILE(PTR)
ADD 1 TO INDX
END-IF
END-PERFORM.
MODIFY MAPIMessage RECIPDISPLAYNAME = RECIPIENT-ADDRESS.
MODIFY MAPIMessage RECIPADDRESS = RECIPIENT-ADDRESS.

MODIFY MAPIMessage @SEND(0).
MODIFY MAPISession SIGNOFF().
DESTROY MAPIMessage.
DESTROY MAPISession.
What you describes reminds me of if you are using an smtp server that is not native to your current logged on network. Remember that your email client must have an account configured for sending emails. If this account is using an smtp that is not native to your network, chances are, your mail will be rejected.
Say for instance your network is acme.com, however you try to send mail on smtp.mail.com. This would not work because your ip is not associated with mail.com.

[Migrated content. Thread originally posted on 22 September 2006]

I have a program (I believe it is a sample on one of the forum threads) that I am using to send emails with attachments through MSMAPI. This program works great with Outlook Express. However, when attempting to use the program with Outlook, the emails are placed in the Outbox, when they are eventually sent, they are immediately returned as undeliverable. When I look at the email in sent items, there is no "from" name/address. I have tried to log in as the user name/password and this does not help. Outlook is being used without Exchange Server. I have tried researching this on Microsoft's website, but I basically don't understand how MAPI might differ with and without Exchange Server where Outlook is concerned. Any suggestions?

Here is my code:

CREATE MAPISESSION OF MSMAPI
LICENSE-KEY "mggthkgogggvmkhinjggnvm"
HANDLE IN MAPISession.
CREATE MAPIMESSAGES OF MSMAPI
LICENSE-KEY"nnmnmninigthkgogggvmkhinjggnvm"
HANDLE IN MAPIMessage.
MODIFY MAPISession DOWNLOADMAIL 0.
MODIFY MAPISession USERNAME= "support@drcanswers.com".
MODIFY MAPISession PASSWORD = "support".

MODIFY MAPISession SIGNON().
INQUIRE MAPISession SESSIONID Session_ID.
MODIFY MAPIMessage SESSIONID = Session_ID.
MODIFY MAPIMessage COMPOSE().
MODIFY MAPIMessage MSGSUBJECT = EMAIL-SUBJECT.
MODIFY MAPIMessage MSGNOTETEXT = EMAIL-MESSAGE.
MOVE 0 TO INDX.
PERFORM VARYING PTR FROM 1 BY 1 UNTIL PTR > 59
IF ATTACHMENT-FILE(PTR) NOT = SPACES
MODIFY MAPIMessage
ATTACHMENTINDEX = INDX
ATTACHMENTPOSITION = INDX
ATTACHMENTPATHNAME = ATTACHMENT-FILE(PTR)
ADD 1 TO INDX
END-IF
END-PERFORM.
MODIFY MAPIMessage RECIPDISPLAYNAME = RECIPIENT-ADDRESS.
MODIFY MAPIMessage RECIPADDRESS = RECIPIENT-ADDRESS.

MODIFY MAPIMessage @SEND(0).
MODIFY MAPISession SIGNOFF().
DESTROY MAPIMessage.
DESTROY MAPISession.
Thank you for your help. I was not able to get Outlook working through MSMAPI - so I changed my code and used the outlook object directly and it worked beautifully.

[Migrated content. Thread originally posted on 22 September 2006]

I have a program (I believe it is a sample on one of the forum threads) that I am using to send emails with attachments through MSMAPI. This program works great with Outlook Express. However, when attempting to use the program with Outlook, the emails are placed in the Outbox, when they are eventually sent, they are immediately returned as undeliverable. When I look at the email in sent items, there is no "from" name/address. I have tried to log in as the user name/password and this does not help. Outlook is being used without Exchange Server. I have tried researching this on Microsoft's website, but I basically don't understand how MAPI might differ with and without Exchange Server where Outlook is concerned. Any suggestions?

Here is my code:

CREATE MAPISESSION OF MSMAPI
LICENSE-KEY "mggthkgogggvmkhinjggnvm"
HANDLE IN MAPISession.
CREATE MAPIMESSAGES OF MSMAPI
LICENSE-KEY"nnmnmninigthkgogggvmkhinjggnvm"
HANDLE IN MAPIMessage.
MODIFY MAPISession DOWNLOADMAIL 0.
MODIFY MAPISession USERNAME= "support@drcanswers.com".
MODIFY MAPISession PASSWORD = "support".

MODIFY MAPISession SIGNON().
INQUIRE MAPISession SESSIONID Session_ID.
MODIFY MAPIMessage SESSIONID = Session_ID.
MODIFY MAPIMessage COMPOSE().
MODIFY MAPIMessage MSGSUBJECT = EMAIL-SUBJECT.
MODIFY MAPIMessage MSGNOTETEXT = EMAIL-MESSAGE.
MOVE 0 TO INDX.
PERFORM VARYING PTR FROM 1 BY 1 UNTIL PTR > 59
IF ATTACHMENT-FILE(PTR) NOT = SPACES
MODIFY MAPIMessage
ATTACHMENTINDEX = INDX
ATTACHMENTPOSITION = INDX
ATTACHMENTPATHNAME = ATTACHMENT-FILE(PTR)
ADD 1 TO INDX
END-IF
END-PERFORM.
MODIFY MAPIMessage RECIPDISPLAYNAME = RECIPIENT-ADDRESS.
MODIFY MAPIMessage RECIPADDRESS = RECIPIENT-ADDRESS.

MODIFY MAPIMessage @SEND(0).
MODIFY MAPISession SIGNOFF().
DESTROY MAPIMessage.
DESTROY MAPISession.
That sounds like Outlook Express has been your default email client and you tried to use Outlook.
It is really not intuitive to deal with. Glad you finally got it working.

[Migrated content. Thread originally posted on 22 September 2006]

I have a program (I believe it is a sample on one of the forum threads) that I am using to send emails with attachments through MSMAPI. This program works great with Outlook Express. However, when attempting to use the program with Outlook, the emails are placed in the Outbox, when they are eventually sent, they are immediately returned as undeliverable. When I look at the email in sent items, there is no "from" name/address. I have tried to log in as the user name/password and this does not help. Outlook is being used without Exchange Server. I have tried researching this on Microsoft's website, but I basically don't understand how MAPI might differ with and without Exchange Server where Outlook is concerned. Any suggestions?

Here is my code:

CREATE MAPISESSION OF MSMAPI
LICENSE-KEY "mggthkgogggvmkhinjggnvm"
HANDLE IN MAPISession.
CREATE MAPIMESSAGES OF MSMAPI
LICENSE-KEY"nnmnmninigthkgogggvmkhinjggnvm"
HANDLE IN MAPIMessage.
MODIFY MAPISession DOWNLOADMAIL 0.
MODIFY MAPISession USERNAME= "support@drcanswers.com".
MODIFY MAPISession PASSWORD = "support".

MODIFY MAPISession SIGNON().
INQUIRE MAPISession SESSIONID Session_ID.
MODIFY MAPIMessage SESSIONID = Session_ID.
MODIFY MAPIMessage COMPOSE().
MODIFY MAPIMessage MSGSUBJECT = EMAIL-SUBJECT.
MODIFY MAPIMessage MSGNOTETEXT = EMAIL-MESSAGE.
MOVE 0 TO INDX.
PERFORM VARYING PTR FROM 1 BY 1 UNTIL PTR > 59
IF ATTACHMENT-FILE(PTR) NOT = SPACES
MODIFY MAPIMessage
ATTACHMENTINDEX = INDX
ATTACHMENTPOSITION = INDX
ATTACHMENTPATHNAME = ATTACHMENT-FILE(PTR)
ADD 1 TO INDX
END-IF
END-PERFORM.
MODIFY MAPIMessage RECIPDISPLAYNAME = RECIPIENT-ADDRESS.
MODIFY MAPIMessage RECIPADDRESS = RECIPIENT-ADDRESS.

MODIFY MAPIMessage @SEND(0).
MODIFY MAPISession SIGNOFF().
DESTROY MAPIMessage.
DESTROY MAPISession.
I actually did have Outlook set as the default client. I only had one email address set up in Outlook. I added a second email address and then it started putting an address in the "from" header. However, it was not the "default" address. By playing with the list of email addresses and making sure the one I wanted to use was at the bottom of the address list, it would put the correct addresses in the "from" header - but still would not send the emails. I read on Microsoft's website, and then based on some information you had posted here - I didn't feel my chances were very good of getting the mapi to work. So, I changed to the actual outlook definition and it is working. Very strange behaviour from Outlook, I think.