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
Solved

Create a new mail in outlook from mht file

Posted on 2010-08-16
8
1,657 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
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Outlook 13 41
HTML Anchor Link Problem 3 35
really easy css change help please 4 17
how to loop through and process two columns in excel 8 18
What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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