?
Solved

Create a new mail in outlook from mht file

Posted on 2010-08-16
8
Medium Priority
?
1,813 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Mailbox Overload?
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Suggested Courses

741 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