Solved

Create a new mail in outlook from mht file

Posted on 2010-08-16
8
1,755 Views
Last Modified: 2012-05-10
Hi!
i have an MHT file which i modify using a batch file
i want to be able to create an outlook "new mail" from it every time i modify
how is it possible to do using vbscript or so?

Thanks!
0
Comment
Question by:m0tek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:Brum07
ID: 33443802
I would use the VBscript here:

http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_23840036.html

to create the email via a VBScript and call the VBScript from your batch file so when the batch file modifies your MHT file it will send out the email.
0
 

Author Comment

by:m0tek
ID: 33443835
Hi ,
thanks ,
however this doesnt use the MHT as the body


Const olMailItem = 0
Dim olkApp, olkSes, olkMsg
On Error Resume Next
Set olkApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If TypeName(olkApp) = "Nothing" Then
    Set olkApp = CreateObject("Outlook.Application")
    Set olkSes = olkApp.GetNamespace("MAPI")
    'Change the Outlook profile name on the next line as needed'
    olkSes.Logon "Outlook"
End If
Set olkMsg = olkApp.CreateItem(olMailItem)
With olkMsg
    'Change the address ont eh next line'
    .Recipients.Add "someone@company.com"
    .Recipients.ResolveAll
    'Change the subject on the next line'
    .Subject = "My Subject"
    'Change the message body on the next line'
    .Body = "Some text."
    .Send
End With
Set olkMsg = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
WScript.Quit

Open in new window

0
 

Author Comment

by:m0tek
ID: 33443869
also - this automatically sends the email - i need the outlook window to open in order to verify the inputs
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 76

Expert Comment

by:David Lee
ID: 33446168
Hi, m0tek.

I modified the code to meet you needs.  I'm not sure that Outlook can handle an .mht file's contents as the body of a message.  
Const olMailItem = 0
Dim olkApp, olkSes, olkMsg, objFSO, objFil
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Change the file name and path on the next line'
Set objFil = objFSO.OpenTextFile("C:\eeTesting\MyFile.mht")
Set olkApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If TypeName(olkApp) = "Nothing" Then
    Set olkApp = CreateObject("Outlook.Application")
    Set olkSes = olkApp.GetNamespace("MAPI")
    'Change the Outlook profile name on the next line as needed'
    olkSes.Logon "Outlook"
End If
Set olkMsg = olkApp.CreateItem(olMailItem)
With olkMsg
    'Change the address on the next line'
    .Recipients.Add "someone@company.com"
    .Recipients.ResolveAll
    'Change the subject on the next line'
    .Subject = "My Subject"
    'Change the message body on the next line'
    .HTMLBody = objFil.ReadAll
    .Display
End With
objFil.Close
Set objFil = Nothing
Set objFSO = Nothing
Set olkMsg = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
WScript.Quit

Open in new window

0
 

Author Comment

by:m0tek
ID: 33461971
Wow!
works perfectly with an HTML file (not MHT)

is it possible to have this run with arguments to replace placeholders in my html file?

in example i have 4 arguments in the html which i want to replace ,

is it possible to replace them using the vbs instead of my batch file?

run mail.vbs argu1 argu2 argu3 argu4

0
 
LVL 76

Expert Comment

by:David Lee
ID: 33462563
Yes, that's possible.  I'll need to know what to each of the four arguments needs to replace in order to modify the code.
0
 

Author Comment

by:m0tek
ID: 33462704
ive attached an HTML File

its an html with text

all of the $ArcSightArg1 , 2  , 3 , 4 will be replaced with text i will have to give out to the vbscript

thanks

test2.htm
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 33462775
Ok.  This should do it.
Const olMailItem = 0
Dim olkApp, olkSes, olkMsg, objFSO, objFil
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Change the file name and path on the next line'
Set objFil = objFSO.OpenTextFile("C:\eeTesting\MyFile.mht")
Set olkApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If TypeName(olkApp) = "Nothing" Then
    Set olkApp = CreateObject("Outlook.Application")
    Set olkSes = olkApp.GetNamespace("MAPI")
    'Change the Outlook profile name on the next line as needed'
    olkSes.Logon "Outlook"
End If
Set olkMsg = olkApp.CreateItem(olMailItem)
With olkMsg
    'Change the address on the next line'
    .Recipients.Add "someone@company.com"
    .Recipients.ResolveAll
    'Change the subject on the next line'
    .Subject = "My Subject"
    'Change the message body on the next line'
    .HTMLBody = objFil.ReadAll
    'Replace text in the body with the arguments'
    .HTMLBody = Replace(.HTMLBody, "$ArcSightARG1", WScript.Arguments(0))
    .HTMLBody = Replace(.HTMLBody, "$ArcSightARG2", WScript.Arguments(1))
    .HTMLBody = Replace(.HTMLBody, "$ArcSightARG3", WScript.Arguments(2))
    .HTMLBody = Replace(.HTMLBody, "$ArcSightARG4", WScript.Arguments(3))
    .Display
End With
objFil.Close
Set objFil = Nothing
Set objFSO = Nothing
Set olkMsg = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
WScript.Quit

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question