Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PB MAPI send fails. Exhibits two types of odd behavior.

Status
Not open for further replies.

LunaRoja

Programmer
Sep 21, 2010
34
US
Hello,

I am using PowerBuilder 11.5, attempting to send a simple message to prove out the process. The steps appear to be straight-forward to me but the mail send always fails. There are two behaviors that may be clues to the problem. I have listed them and a code snippet (edited to not include actual email addresses) below.

The two odd behaviors are:
1) For the statement (from snippet): <ml_msg.recipient[1].address = "someone@someplace.com">, if the address is valid and is entered in the standard format <x@y.com>, the outlook address book pops up. If I preceed the address with a colon <":someone@someplace.com"> the address book does not pop up. Does this symptom indicate some kind of problem establishing the address? I have tried multiple variations for entering the address with no success.
2) The statement <ml_rtn = iml_sesn.mailsend( )> fails with "mailreturnfailure!” even though the "ml_msg" structure appears to be set up correctly. I have tried several variations and searched the web but I cannot get this last bit to work. We are using MAPI to extract attachments from received mail so I know the MAPI service is functioning.

The mailrecipient property contains one entry. It seems correct to me and looks like this:
===============
[] mailrecipient [1]
<> blob entryid
<> mailrecipienttype recipienttype = mailto!
<> powerobject classdefinition
<> string address = "someone@someplace.com"
<> string name = "NameOfTheRecipient"
===============

Thanks for your time and your help...

==== Code Begin ===
MailMessage ml_msg
MailReturnCode ml_rtn
string ls_msg = ""

// instantiate the mail session object and perform one-time operations
If Not IsValid(iml_sesn) Then
iml_sesn = Create MailSession
// log onto mail
ml_rtn = iml_sesn.maillogon(mailNewSession!)
// was the logon successful?
if ml_rtn = mailReturnSuccess! Then
ib_logonsuccessful = True
// set some of the mail properties
ml_msg.subject = "Test MAPI Send"
ml_msg.recipient[1].address = "someone@someplace.com"
ml_msg.recipient[1].Name = "NameOfTheRecipient"
Else
// construct part of user error message
If ml_rtn = mailReturnLoginFailure! Then
ls_msg = "The mail service indicates that a mail login failure occured."
Elseif ml_rtn = mailReturnInsufficientMemory! Then
ls_msg = "The mail service has indicated that there was insufficient memory to complete the login."
Elseif ml_rtn = mailreturntooManySessions! Then
ls_msg = "The mail service has indicated that there are too many sessions open to complete the login."
End If
End If
End If

// if the program could not log on successfully, notify the user. But only do it once.
If not ib_logonsuccessful and not ib_logonfailmsgsenttouser Then
// make sure another message is not sent
ib_logonfailmsgsenttouser = true
// notify the user that their mail connection did not succeed
If ls_msg <> "" Then
// there is a clarifying message, attach it to the generic failure message
ls_msg = "The program failed to connect to the mail service. ~n~n" + ls_msg
Else
ls_msg = "The program failed to connect to the mail service."
End If
Messagebox("Mail Connection Failure",ls_msg,Exclamation!)
End If

// do not do any further processing if the logon failed
If not ib_logonsuccessful Then Return

// build the message
ml_msg.notetext="A simple test of mail functionality."

// update the session with current information
iml_sesn.mailaddress( ml_msg)

// send the message
ml_rtn = iml_sesn.mailsend( )
====== Code End ====

 
Code from Help:
Code:
mailSession mSes
mailReturnCode mRet
mailMessage mMsg
// Create a mail session
mSes = create mailSession
// Log on to the session
mRet = mSes.mailLogon(mailNewSession!)
IF mRet <> mailReturnSuccess! THEN
   MessageBox("Mail", 'Logon failed.')
    RETURN
END IF

// Populate the mailMessage structure
mMsg.Subject = mle_subject.Text
mMsg.NoteText = 'Luncheon at 12:15'
mMsg.Recipient[1].name = 'Smith, John'
mMsg.Recipient[2].name = 'Shaw, Sue'

// Send the mail

mRet = mSes.mailSend(mMsg)
IF mRet <> mailReturnSuccess! THEN
    MessageBox("Mail Send", 'Mail not sent')
    RETURN
END IF
mSes.mailLogoff()

DESTROY mSes

Have you tried
ml_rtn = iml_sesn.mailsend(ml_msg) ?

Matt


"Nature forges everything on the anvil of time"
 
Thanks mbalent! I did not notice an example which included sending the mail message object as an argument.

I still appear to be having issues with the email address, but I think I might know how to work through that one.

Thanks again for the quick reply and good advice!

LR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top