Visual Basic 6: Read MSG files and extract content - vb6

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.

Related

Crash when using SafeMailItem (fault in mso20win32client.dll)

We use Redemption since many years. Since few days many of our clients have issues when they use our plugin for Outlook. We changed nothing in our app.
I did some traces and found that the line Set CourielOutlook = New Redemption.SafeMailItem makes the app to crash. Events viewer show that the fault is in mso20win32client.dll.
I tried to find the problem by create a simple app doing the same thing and there is no problem with this one!!?
I found that if I rename the original app with a new name (AddinOutlook.exe to AddinOutlook2.exe), the app doesn't crash anymore!
If I rename my simple app to AddinOutlook.exe, it crashes!
I tried many things in Outlook (deleting and recreating the profile, deleting and recreating the account, uninstall and reinstall Office 365). The problem still there.
After deleting and recreating the profile, it works the first time, but after that never (except if I rename the exe).
Any idea?
Here is my simple test app:
Dim Outlook As Outlook.Application
Dim Item As Object
Dim Namespace As Object
Dim CourielOutlook As Object 'Redemption.SafeMailItem
Set Outlook = New Outlook.Application
If Not Outlook Is Nothing Then
On Error Resume Next
Err.Clear
Set Namespace = Outlook.GetNamespace("MAPI")
If Err.Number <> 0 Then
Call Namespace.Logon(vbNullString, vbNullString, False)
End If
If Err.Number = 0 Then
If TypeName(Outlook.ActiveWindow) = "Inspector" Then
Call AjouterElement(Outlook.ActiveInspector.CurrentItem)
Set CourielOutlook = New Redemption.SafeMailItem
CourielOutlook.Item = Outlook.ActiveInspector.CurrentItem
'...
ElseIf TypeName(Outlook.ActiveWindow) = "Explorer" Then
For Each Item In Outlook.ActiveExplorer.Selection
Set CourielOutlook = New Redemption.SafeMailItem
CourielOutlook.Item = Item
'...
Next
End If
End If
End If
Set Outlook = Nothing

VBA : Paste Word.Table into Outlook email

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.

referencing WinSCP COM library from VB6

I am trying to use the WinSCP COM library on a old VB6 project I have (it's a legacy application that generates an OCX file, I think we have to use VB6 for it but not 100% sure).
Anyway we want to implement SFTP, and WinSCP can do that readily.
I registered the COM object, and can see the WinSCPNet type library when I go to add the reference. However I can't see the properties/methods of the classes when I look at the library in the object browser. Further, this code fails, it does not get to the 3rd MsgBox ("In SendWinSCP4"), it returns from the function at that point, I think because the property UserName is not exposed.
MsgBox ("in SendWinSCP")
Dim session As WinSCPnet.session
Dim sessionOptions As WinSCPnet.sessionOptions
Dim transferOptions As WinSCPnet.transferOptions
Set session = New WinSCPnet.session
Set sessionOptions = New WinSCPnet.sessionOptions
Set transferOptions = New WinSCPnet.transferOptions
MsgBox ("in SendWinSCP3")
sessionOptions.Protocol = Protocol_Sftp
sessionOptions.HostName = "example.com"
sessionOptions.UserName = "user"
sessionOptions.Password = "example.com"
sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
MsgBox ("in SendWinSCP4 " & sessionOptions.HostName & "!")
See above, using On Error Resume Next got me past the error.

Lotus Notes: Add Workspace Icon using Lotusscript

I would like to create a LotusScript "script" which would add a specified database to a users workspace. What is the best way to create and , especially, distribute such a script to the users? The users have Microsoft Outlook email and do not use Lotus Notes mail.
You can just call an URL like Notes://Server/Path/Database.nsf from an email you can send to your users.
You can find more details about URL syntax here
In your answer you have two questions: create script and distribute it.
0. LotusScript for adding database icons
You can use NotesUIWorkspace.AddDatabase method to add database icons to a users workspace:
Dim ws As New NotesUIWorkspace
'...
ws.AddDatabase("Your DB0 Server", "Your DB0 FilePath")
ws.AddDatabase("Your DB1 Server", "Your DB1 FilePath")
ws.AddDatabase("Your DB2 Server", "Your DB2 FilePath")
'...
1. Distribution of any script
You can send the Notes URL to users which would run your script. For this you need to create a Form which run your script in the PostOpen event:
Sub Postopen(Source As Notesuidocument)
Dim ws As New NotesUIWorkspace
'Your script here
Call ws.CurrentDocument.Close
End Sub
So, is better to create profile document with such a form and send URL of this document to users:
Dim ses As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim mdoc As NotesDocument
Dim body As NotesMIMEEntity
Dim stream As NotesStream
Dim nname As NotesName
Set db = ses.CurrentDatabase
Set doc = db.GetProfileDocument("YourProfileDocument")
ses.ConvertMIME = False
Set mdoc = db.CreateDocument
mdoc.SendTo = "Your_users_mail#domain.foo"
mdoc.Subject = "Take a look"
Set stream = ses.CreateStream
Set body = mdoc.CreateMIMEEntity
Set nname = ses.CreateName(db.Server)
Call stream.WriteText({Please open this link.})
Call body.SetContentFromText(stream, "text/html;charset=utf-8", ENC_IDENTITY_8BIT)
Call mdoc.Send(False)
In other hand if you want just to add some databases without any computations then you don't need such a script. As suggested by Knut Herrmann:
You could just call an URL like Notes://Server/Path/Database.nsf.
But beware, it does not add database icons to workspace in earlier versions of Lotus Notes (7 or earlier).

late binding issue with outlook mailitem.save method

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

Resources