|
|
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
|
|
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
"zbud" <zbud[ at ]cfl.rr.com> wrote in message news:1137636041.051163.234090[ at ]g47g2000cwa.googlegroups.com...
[Quoted Text] > 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 >
|
|
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
|
|
Redemption SafeMailItem doesn't have any arguments for its Send method.
-- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm
"zbud" <zbud[ at ]cfl.rr.com> wrote in message news:1137724140.429738.68840[ at ]g43g2000cwa.googlegroups.com...
[Quoted Text] >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 >
|
|
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
Ken Slovak - [MVP - Outlook] wrote:
[Quoted Text] > Redemption SafeMailItem doesn't have any arguments for its Send method. > > -- > Ken Slovak > [MVP - Outlook] > http://www.slovaktech.com> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 > Reminder Manager, Extended Reminders, Attachment Options > http://www.slovaktech.com/products.htm> > > "zbud" <zbud[ at ]cfl.rr.com> wrote in message > news:1137724140.429738.68840[ at ]g43g2000cwa.googlegroups.com... > >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 > >
|
|
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
"zbud" <zbud[ at ]cfl.rr.com> wrote in message news:1137816360.855152.115840[ at ]g43g2000cwa.googlegroups.com...
[Quoted Text] > 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 > > Ken Slovak - [MVP - Outlook] wrote: >> Redemption SafeMailItem doesn't have any arguments for its Send method. >> >> -- >> Ken Slovak >> [MVP - Outlook] >> http://www.slovaktech.com>> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 >> Reminder Manager, Extended Reminders, Attachment Options >> http://www.slovaktech.com/products.htm>> >> >> "zbud" <zbud[ at ]cfl.rr.com> wrote in message >> news:1137724140.429738.68840[ at ]g43g2000cwa.googlegroups.com... >> >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 >> > >
|
|
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
|
|
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
"zbud" <zbud[ at ]cfl.rr.com> wrote in message news:1137890863.541219.155500[ at ]o13g2000cwo.googlegroups.com...
[Quoted Text] > 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 >
|
|
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
|
|
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
"zbud" <zbud[ at ]cfl.rr.com> wrote in message news:1138020489.534276.15390[ at ]g44g2000cwa.googlegroups.com...
[Quoted Text] > 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 >
|
|
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
|
|
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
"zbud" <zbud[ at ]cfl.rr.com> wrote in message news:1138038345.771757.143740[ at ]g44g2000cwa.googlegroups.com...
[Quoted Text] > 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 >
|
|
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
|
|
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
"zbud" <zbud[ at ]cfl.rr.com> wrote in message news:1138543844.894060.305480[ at ]z14g2000cwz.googlegroups.com...
[Quoted Text] > 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 >
|
|
I tired this code, but it must not be right ??
strEntryID = objSession.GetDefaultFolder(CdoDefaultFolderSentItems).ID
SafeObjMessage.Fields.Add PR_SENTMAIL_ENTRYID, strEntryID
Bud
|
|
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
"zbud" <zbud[ at ]cfl.rr.com> wrote in message news:1138767252.494046.234290[ at ]z14g2000cwz.googlegroups.com...
[Quoted Text] >I tired this code, but it must not be right ?? > > strEntryID = objSession.GetDefaultFolder(CdoDefaultFolderSentItems).ID > > SafeObjMessage.Fields.Add PR_SENTMAIL_ENTRYID, strEntryID > > Bud >
|
|
|