Solved

Create a new mail in outlook from mht file

Posted on 2010-08-16
8
1,521 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
If you don't know how to downgrade, my instructions below should be helpful.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now