I have the below VBA code which i run to create a reply email.
Dim Reply As Outlook.MailItem
Dim Original As Outlook.MailItem
Set Original = Application.ActiveExplorer.Selection(1)
Set Reply = Original.ReplyAll
Reply.Subject = "RE: " & Original.Subject
Reply.Display
I have the following variable and have been unsuccessfully trying to paste it into "Reply" above.
Dim tTable As Word.Table
Word is used as an email editor in Outlook. You can use the WordEditor property of the Inspector class to get an instance of the Document class which represents the Body of the email. Thus, you will be able to use objects, their properties and methods available in the Word object model when working with item bodies.
You can read about all possible ways in the Chapter 17: Working with Item Bodies article in MSDN.
Related
I have created a VB6 application which contains a service to basically send and receive emails,the service uses a service account and mapi profile configured in Windows 2003 serverR2.
This was working when both exchange server and domain account were in the same network. Once the exchange server got changed the service is unable to send or receive emails giving error
Microsoft Exchange is not available. Either there are network problems or the Exchange computer is down for maintenance. [Microsoft Exchange Information Store - [MAPI_E_FAILONEPROVIDER(8004011D)]], Collaboration Data Objects.
I have searched this error but I wasn't able to gather all as the explanation is for same network.
Anyone could you please advice what can I do to resolve this ?
Thanks,
MAPI has been discontinued by Microsift as suggested by #bob77 also.
I would recommend to use SMTP or EWS.
That being said if you still want to go with it.
Please find the working code below:
Set objMAPI = New MAPI.Session
objMAPI.Logon ShowDialog:=False, NewSession:=False, ProfileInfo:=gobjINI.gstrExchangeServer & vbLf & gobjINI.gstrProfile
'Add a new mesage to the OUtbo Messages Collection
Set objMSG = objMAPI.Outbox.Messages.Add
Set fsoMy_File_Sys_Obj = New FileSystemObject
'Add the recipient list specified in INI File
'Check if this is a multiple Recipient List (names or groups seperated by semicolons!)
If InStr(1, Recipients, ";") Then
objMSG.Recipients.AddMultiple Recipients, CdoTo
objMSG.Recipients.Resolve
Else
'This section is for handling of single recipient name
'Be aware that this may be an email group list name !
Set objRecipients = objMSG.Recipients.Add(Recipients)
objRecipients.Resolve
End If
'Add an attachment if needed
If Attachment_Name <> "" Then
bolAttach_File_Exists = fsoMy_File_Sys_Obj.FileExists(Attachment_Path)
If bolAttach_File_Exists = True Then
'Open the attachment file and add it to the message text
Set tsAttachment = fsoMy_File_Sys_Obj.OpenTextFile(Attachment_Path)
Do While Not tsAttachment.AtEndOfStream
strAttachment_Read = tsAttachment.ReadLine
Message = Message & strAttachment_Read & vbCrLf
Loop
tsAttachment.Close
Else
gobjMAPI.MailSend gobjINI.gstrMailRecipients, "Email Send - Attachment Addition", "Attempted To Attach A File That Does Not Exist", "", ""
End If
End If
'Add Subject Line, Message Content and Send Message
objMSG.Subject = Subject
objMSG.Text = Message
objMSG.Importance = mapiHigh
'The Update method adds all our assignments to collecttion
objMSG.Update
'Now let's actually send the message
objMSG.Send
'End MAPI Session
objMAPI.Logoff
Set objMAPI = Nothing
What's the proper way to set a MailItem as read before opening or set the value suppress_receipt in PR_MESSAGE_FLAGS?
Looking at http://msdn.microsoft.com/en-us/library/office/cc815395(v=office.12).aspx my code is:
MailItem x = item as MailItem;
x.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E070003",35);
I got 35 from other read mails using OutlookSpy, assuming it contains the boolean flag for "Read".
Running this code gets me the exception "The operation failed".
Any ideas?
Thanks.
You cannot do that in the Outlook Object Model. On the MAPI level, you need to call IMessage::SetReadFlag(SUPPRESS_RECEIPT), but you will need C++ or Delphi for that.
If using Redemption (I am its author) is an option, you can use RDOMail.MarkRead(SuppressReceipt) (can be called from any language)
Use:
string PR_CLIENT_READ = "http://schemas.microsoft.com/mapi/proptag/0x0E070003"; omMailItem.PropertyAccessor.SetProperty(PR_CLIENT_READ, 0x09);
Worked for me..
I have a function that re-creates an email using the contents of another email (using the Outlook Redemption library). I have almost finished converting it to early binding (I am using Option Strict ON in vb.net), but visual studio 2010 underlines the .save and .move lines with the error "option strict on disallows late binding."
The code is:
'Use Redemption Library function to re-create email
Dim sItem As Redemption.SafeMailItem
Dim oItem As Object
sItem = New Redemption.SafeMailItem
oItem = myOlApp.Session.GetSharedDefaultFolder(myRecipient, Outlook.OlDefaultFolders.olFolderDrafts).Items.Add(Outlook.OlItemType.olMailItem)
With sItem
.Item = oItem
.Import(tempfilepath, 3) 'olMSG, olRFC822 and olTNEF formats are supported
.Save()
.Move(myolfolder)
End With
Having resolved the other late binding errors I cannot see why the two methods are flagging as a problem.
Help
Lewis
You get that error because SafeMailItem obly implements properties and methods blocked by Outlook.
Since Save and Move are not blocked, SafeMailItem does not implement them, but it is smart enough to pass them through when you are using late binding. Invoke those methods using the original Outlook item:
With sItem
.Item = oItem
.Import(tempfilepath, 3) 'olMSG, olRFC822 and olTNEF formats are supported
oItem.Save()
oItem.Move(myolfolder)
End With
I need to mimic the adress book control in an Outlook VSTO project. It would be much simpler to use the real control, isn't it?
So, do you know a way to expose the address book control, and get what's selected within, of course?
Edit: Never mind, re-creating a basic version of the control will be way easyer.
Solution: third party Redemption library offer this feature.
RedemptionLoader.RDOSession.AddressBook.ShowAddressBook(...)
You don't need to use a third party addin. you can do it with this:
http://msdn.microsoft.com/en-us/library/office/ff868361.aspx
this code below is in VBA but you can easily convert it to C#:
Sub SelectRecipients()
Dim oMsg As MailItem
Set oMsg = Application.CreateItem(olMailItem)
Dim oDialog As SelectNamesDialog
Set oDialog = Application.Session.GetSelectNamesDialog
With oDialog
.InitialAddressList = _
Application.Session.GetGlobalAddressList
.Recipients = oMsg.Recipients
If .Display Then
'Recipients Resolved
oMsg.Subject = "Hello"
oMsg.Send
End If
End With
End Sub
I would like to read MSG file stored on the filesystem and do the following:
Read the body text of the msg file.
Open and save the attachments in the MSG file.
Is it possible using the msoutl.olb#Microsoft Outlook 10.0 Object Library?
I would like to avoid using Outlook Redemption v. 4.7 based
on question MSG Read Stackoverflow question
Thank you.
I believe you can. Try adding a reference to the Outlook 10 object library and then try this code:
Dim OL As Outlook.Application
Dim Msg As Outlook.MailItem
Set OL = New Outlook.Application
Set Msg = OL.CreateItemFromTemplate("c:\msg.msg")
' now use msg to get at the email parts
MsgBox Msg.Subject
Set OL = Nothing
Set Msg = Nothing
I can't vouch for any of the methods or properties of your Outlook.MailItem object (msg) but give it a shot and see.