Redemption Doesn't ByPass Outllok 2003 Security

Z

zbud

Trying to send email from MS Access 2003 using CDO 1.21 and the RTF DLL
in MS KB http://support.microsoft.com/?kbid=172038. This all works fine
except for dealing with Outlook 2003 security that advises a program is
trying to send a message on your behalf.

installed the Redemption library and am using the following code
snippet, which still works but still getting the security prompt. There
is also a "mapi_e_logon_failed" error is Outlook is not open.

Any help is appreciated.

Bud

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False, 0

' Create a new message
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Update
MessageID = objMessage.ID

'write the RTF String
bRet = writertf(objSession.Name, objMessage.ID, _
objMessage.StoreID, txtRTf)
If Not bRet = 0 Then
MsgBox "RTF Not Written Successfully", vbOKOnly, "VBSendRTF
Warning"
End If

'Clear our current variable
Set objMessage = Nothing

Set utils = CreateObject("Redemption.MAPIUtils")
utils.MAPIOBJECT = objSession.MAPIOBJECT

Set SafeObjMessage = CreateObject("Redemption.SafeMailItem")

' Get our message
Set SafeObjMessage = objSession.GetMessage(MessageID)
SafeObjMessage.Subject = strSubj
Set objRecipient = SafeObjMessage.Recipients.Add
objRecipient.Name = strEmail2
Set objAttachment = SafeObjMessage.Attachments.Add
objAttachment.Type = CdoFileData
objAttachment.ReadFromFile strPath
objAttachment.Source = strPath
objAttachment.Name = strReport

SafeObjMessage.Update

' Send the Message
SafeObjMessage.Send ShowDialog:=True
objSession.Logoff
utils.Cleanup
Set utils = Nothing
 
D

Dmitry Streblechenko

Change the line
Set SafeObjMessage = objSession.GetMessage(MessageID)
to
SafeObjMessage.Item = objSession.GetMessage(MessageID)

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Z

zbud

I changed the code line as you suggested and redid the attachemnt part
but am still getting the Outlook security dialog ?? The code now looks
like this :

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False, 0

' Create a new message
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Update
MessageID = objMessage.ID

'write the RTF String
bRet = writertf(objSession.Name, objMessage.ID, _
objMessage.StoreID, txtRTf)
If Not bRet = 0 Then
MsgBox "RTF Not Written Successfully", vbOKOnly, "VBSendRTF
Warning"
End If

'Add the attachment

Set objAttachment = objMessage.Attachments.Add
objAttachment.Type = CdoFileData
objAttachment.ReadFromFile strPath
objAttachment.Source = strPath
objAttachment.Name = strReport
objMessage.Update

'Clear our current variable
Set objMessage = Nothing

Set utils = CreateObject("Redemption.MAPIUtils")
utils.MAPIOBJECT = objSession.MAPIOBJECT

Set SafeObjMessage = CreateObject("Redemption.SafeMailItem")

' Get our message and add subject and recipient
SafeObjMessage.Item = objSession.GetMessage(MessageID)
SafeObjMessage.Subject = strSubj
SafeObjMessage.Recipients.Add strEmail2
SafeObjMessage.Update

' Send the Message
SafeObjMessage.Send ShowDialog:=True
objSession.Logoff
utils.Cleanup
Set utils = Nothing

any help is appreciated
Bud
 
K

Ken Slovak - [MVP - Outlook]

Redemption SafeMailItem doesn't have any arguments for its Send method.
 
Z

zbud

thanks for the tip, that allowed me to bypass the Outlook security, But
now the message doesn't have any text returned from the RTF function.

Also need some help with why I get a CDO login failure if outlook is
not open.

Thanks

Bud
 
D

Dmitry Streblechenko

1. If you are using Redemption, you can simply use the MailItem.RtfBody
property
2. Does Outlook prompt you for the user credentials when you open it?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Z

zbud

was able to handle the RTF problem by adding the attachment BEFORE
calling the RTF write function in MSKB
http://support.microsoft.com/?kbid=172038.

Understand that you can not logon to a profile in Outlook 2003 when
outlook is closed ????

Outlook deos not prompt for user credentials on my machine.

Guess I could check to make sure outlook is open and prompt the user to
do so if it's not, but was hoping for something more elegant

thanks for any thoughts

Bud

Bud
 
D

Dmitry Streblechenko

No, Outlook is a MAPI client and it simply log to a profile when it starts.
You can log to the same profile without using Outlook in Extended MAPI, CDO
1.21 or Redemption.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Z

zbud

Since multiple users will be working with this solution, is it possible
then to create am anonymous profile as shown in the CDO help file and
have the resultant message placed in the users outlook outbox for
sending the next time they start outlook ?

Thanks for your help and patience

Bud
 
D

Dmitry Streblechenko

You cannot create a temporary profile using Outlook Object Model.
Are you running Outlook in a service that is accessed by multiple users?
Don't do that.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Z

zbud

no each user has their own outlook 2003 application installed on their
machine.

What's the best way to handle the mapi logon considering they may not
have Outlook open and I have to use CDO to handle the RTF write
function I mentioned in previous messages. I have code to see if
Outlook is running and can have a msgbox open to tell them to start it,
but would like something a little more automatic..

Thanks

Bud
 
D

Dmitry Streblechenko

Session.Logon with no parameter (no profile name = "") will start the
default profile.
Your code specifies FALSE in the fourth parameter (NewSession), which *will*
produce an error if there is no active MAPI session. Use TRUE instead. Or
call Logon with no parameters.
If Outlook is already running, you'll be better off setting
Session.MAPIOBJECT to Namespace.MAPIOBJECT in case the user uses a
non-default profile rather than call Session.Logon.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Z

zbud

Setting the 4th parameter to true generates the e_mapi_logon error
regardless of whether Outlook is open or not.

Opening the session without params prompts with the profile dialog box
and then password if there is one.

Setting the 4th param to false works when outlook is open, the message
is correctly formed in the outbox, and it sends on the next
send/receive, but a copy remains in the outbox and no copy is in the
sent items folder ?

Here's the function as it stands with the session params remmed out:

Function SendRTF(strSubj As String, strEmail2 As String, strReport As
String, _
strPath As String) As Boolean
Dim objSession, objMessage, objMessageFilter As Object
Dim MessageID As String, objRecipient As Object
Dim objAttachment As Object
Dim bRet As Integer, utils As Object
Dim SafeObjMessage As Object

Set objSession = CreateObject("MAPI.Session")
objSession.Logon ' if using params "", "", False, True, 0

' Create a new message
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Update
MessageID = objMessage.ID

'Add the attachment


Set objAttachment = objMessage.Attachments.Add
objAttachment.Type = CdoFileData
objAttachment.ReadFromFile strPath
objAttachment.Source = strPath
objAttachment.Name = strReport
objAttachment.Position = -1
objMessage.Update

'write the RTF String
bRet = writertf(objSession.Name, objMessage.ID, _
objMessage.StoreID, txtRTf)
If Not bRet = 0 Then
MsgBox "RTF Not Written Successfully", vbOKOnly, "VBSendRTF
Warning"
End If


'Clear our current variable
Set objMessage = Nothing

Set utils = CreateObject("Redemption.MAPIUtils")
utils.MAPIOBJECT = objSession.MAPIOBJECT

Set SafeObjMessage = CreateObject("Redemption.SafeMailItem")

' Get our message and add subject and recipient
SafeObjMessage.Item = objSession.GetMessage(MessageID)
SafeObjMessage.Subject = strSubj
SafeObjMessage.Recipients.Add strEmail2
'SafeObjMessage.Update

' Send the Message
SafeObjMessage.Send 'ShowDialog:=True
objSession.Logoff
utils.Cleanup
Set utils = Nothing
End Function
 
D

Dmitry Streblechenko

You can try to explicitly specify the profile name or turn "prompt for the
profile" in the Mail Control Panel applet.
To make sure the message gets moved to the Sent Items folder, set the
PR_SENTMAIL_ENTRYID (0x0E0A0102) property to the entry id of the Sent Items
folder.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Z

zbud

I tired this code, but it must not be right ??

strEntryID = objSession.GetDefaultFolder(CdoDefaultFolderSentItems).ID

SafeObjMessage.Fields.Add PR_SENTMAIL_ENTRYID, strEntryID

Bud
 
D

Dmitry Streblechenko

That's CDO syntax. In Redemption you need something like:

SafeObjMessage.Fields(PR_SENTMAIL_ENTRYID) = strEntryID

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top