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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Mail with MAPI Problem

Status
Not open for further replies.

sandra45

Technical User
Apr 3, 2003
72
ID
Hi all, I have a problem in sending out e-mail using MAPI. The message does go via Outlook Outbox folder and then Sent folder. However, it does not come to the recipient's e-mail address. Can anyone help me here please? The code is as shown below:
Private Sub Form_Load()
MAPISession1.DownLoadMail = False
MAPISession1.UserName = "my username"
MAPISession1.Password = "my password"
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
End Sub

Private Sub cmdPublish_Click()
MAPIMessages1.Compose
MAPIMessages1.MsgSubject = "Subject here"
MAPIMessages1.MsgNoteText = "Body message here"
MAPIMessages1.RecipDisplayName = "display name here"
MAPIMessages1.RecipAddress = "recipient's email address here"
MAPIMessages1.AttachmentPathName = "Attachment here" MAPIMessages1.Send
End Sub

Private Sub Form_Unload(Cancel As Integer)
MAPISession1.SignOff
End Sub

Is it because of the MAPIMessages1.RecipDisplayName or RecipAddress? I have included the recipient's email address under MAPIMessages1.RecipAddress only, and also tried to include "SMTP:"& but the result is the same, what is wrong here? Please help, thanks.

Regards,
Sandra
 
I have a similar routine that works. The only difference I see is that I have
Code:
MAPISession1.NewSession = False
Otherwise my code is the same.

What version of Outlook are you using? I remember having a bit of a ding-dong with Microsoft Support about this, as Outlook 97 wouldn't behave itself. In the end MS sent me a copy of Outlook 2000, and I moved to CDO as it was much more reliable. If you can use CDO I can post some code...

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Try just setting the RecipDisplayName to the SMTP address in this form:

MAPIMessages1.RecipDisplayName = "[SMTP:joe@xyz.com]"

and leaving the RecipAddress empty.

Paul Bent
Northwind IT Systems
 
Hi guys, I've tried and didn't work. I'm using Outlook XP, is there any problems using MAPI with Outlook XP? This is frustrating, because it shows the message in Sent folder, however it does not reach the recipient.

Regards,
Sandra
 
Hi all, sorry about the version, it should be Mic. Outlook 2002. My OS is Win2000Professional. Probably I should let you know the whole story about what I'm doing:
I'm writing an application in VB that will retrieve email addresses stored in a database in our web host company, this is ok and working.
I also append MAPI session and control on this application. With the email addresses retrieved above, the user can then choose a file to attach, and send the attachment to all parties according to their email addresses.
It all works, no error message. I tried to send myself an email using this application. It goes through Outbox, and Sent folder, BUT it does not reach the recipient. Then I tried composing new email directly from Outlook and send to myself, it works. Which means the outgoing mail process is working properly with Outlook, however, it does not work if I send via my application even though it goes through Outlook's Outbox and Sent folders.

Is there something to do with the outgoing mail configuration? We are using mail server from a company to send e-mail and the outgoing mail server points to smtp of that company account. All work fine with direct email sending with Outlook but not if via application. Please help!!! I'm getting nervous about this. Thanks.

Regards,
Sandra
 
Sandra,

while I have not done a lot with MAPI directly, I have worked a lot with VB programs sending email through outlook.

Because of the security feature in Outllok 2002 sending email is still a bit of a hasle, but you can download redemption to bypass this:
Once you download this you can send via tis code:

Dim SafeItem, oItem
Set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an instance of Redemption.SafeMailItem
Set oItem = Application.CreateItem(0) 'Create a new message
SafeItem.Item = oItem 'set Item property
SafeItem.Recipients.Add "Address"
SafeItem.Recipients.ResolveAll
SafeItem.Subject = "Important Message"
SafeItem.body = message
SafeItem.Send

Set Btn = Application.ActiveExplorer.CommandBars.FindControl(1, 5488)

Btn.Execute

Let me know if this works for you.

Billy



Billy Ballard

For in the past, Lies the future.
 
Hi Billy, thanks, I'll try it. Do we need to have Outlook opened while sending? I see this is also a hassle to have Outlook opened first before the email can be sent out.

Regards,
Sandra
 
With the code I sent yes, outlook should be open. It is also an option to create an instance of Outlook and send it from that.

Billy Ballard

For in the past, Lies the future.
 
Hi Billy, there's error message for this line:
Set oItem = Application.CreateItem(0) 'Create a new message

Application is not defined. What application do you mean here? Is it Outlook?

Regards,
Sandra
 
Sandra, here is a copy of te code in my DLL. I pass it the values for the address to send, subject and body.

Sorry about the shortened copy, it is what I was using in a macro directly in Outlook.

Public Function sender(ByVal fwdmsg, header, address)
Dim namespace


Set Application = CreateObject("Outlook.Application")

Set namespace = Application.GetNamespace("MAPI")

namespace.Logon

Dim SafeItem, oItem
Set SafeItem = CreateObject("Redemption.SafeMailItem") 'Create an instance of Redemption.SafeMailItem
Set oItem = Application.CreateItem(0) 'Create a new message
SafeItem.Item = oItem 'set Item property
SafeItem.Recipients.Add address
SafeItem.Recipients.ResolveAll
SafeItem.Subject = header
SafeItem.Body = fwdmsg
SafeItem.Send

'Outlook 2000
'MailItem.Send
'Set Utils = CreateObject("Redemption.MAPIUtils")


'Outlook XP

'MailItem.Send
Set Btn = Application.ActiveExplorer.CommandBars.FindControl(1, 5488)
Btn.Execute

End Function

Billy Ballard

For in the past, Lies the future.
 
I'm using Outlook XP/2002. This worked for me:
Code:
  Dim objOlApp As Outlook.Application
  Dim objOlItem As Outlook.MailItem
  
  Set objOlApp = New Outlook.Application
  Set objOlItem = objOlApp.CreateItem(olMailItem)
  
  With objOlItem
    .Recipients.Add "someone@domain.com"
    .Subject = "Subject"
    .Body = "Message"
    .Attachments.Add "Z:\TEST.TXT"
    .Send
  End With
  Set objOlItem = Nothing
  objOlApp.Quit
  Set objOlApp = Nothing


Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top