Solved

Create a new mail in outlook from mht file

Posted on 2010-08-16
8
1,577 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

911 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

19 Experts available now in Live!

Get 1:1 Help Now