Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert this vbscript in HTA ?

Status
Not open for further replies.

hackoo

Programmer
Jan 31, 2003
28
TN
Hi !
I want to make a small dialog box asking for a few options, and then I want to take those options and send them via e-mail with attachment.
I already have a VBS script that sends e-mail, and I need to use HTA for my form.
How can I combine the VBS script into my HTA, or how can I pass the HTA values to my VBS script?
Here is my mail VBScript:
Code:
sub main()
Dim messageHTML
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = [stuff from the HTA] 
objMessage.From = [stuff from the HTA]
objMessage.To = [stuff from the HTA] 
objMessage.TextBody = [stuff from the HTA]
File= [stuff from the HTA] 'path of attachement
messageHTML="This an example in HTML sended by hackoo"
 
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2 
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = [stuff from the HTA]
objMessage.Configuration.Fields.Item _
("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25 
objMessage.Configuration.Fields.Update

objMessage.HTMLBody="<center><font size=4 FACE=Tahoma Color=red>"&messageHTML&"<br><br><img src=[URL unfurl="true"]http://photomaniak.com/upload/out.php/i1102064_IDNlogo.gif>"[/URL]
objMessage.AddAttachment(File) ' adding Attachment
objMessage.Send
 
	If Err.Number <>0 Then
			MsgBox Err.Description,16,"Error"
			msgbox "The mail isn't sended !",16,"Information"
		Else
		msgbox "The mail is sended sucessfully !",64,"Information"
	End If
		On Error GoTo 0 
 end sub
Call main
Thank you !
Best Regards !
 
Hi ! I founded a good example on the Net dealing with my aim.Just i modified it to add an attachment and a signature in a HTML Mode with image (^_^) and here is the code modified by me that can help someone else !
Please take a few time to test this and tell me your result !
With My Best Regards !
Code:
<html> 
<head> 
<HTA:APPLICATION 
    ICON="icon.ico"
    APPLICATIONNAME = "SMTP Mail Client" 
    BORDER="dialog"
    BORDERSTYLE="complex"
    CONTEXTMENU="no"
    SYSMENU="yes"
    MAXIMIZEBUTTON="no"
    SCROLL="no" 
>

<title>SMTP Mail Client Modified by Hackoo (^_^)</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<style>
    body{
        background-color: lightblue;
    }
    label,.btn{
        font-weight: bold;
    }
</style>
<script language="VBScript">
    
    'Const SMTPSERVER = "smtp.xxxx.xxx"
    
    Sub window_onload()
        CenterWindow 415, 600
    End Sub
    
    Sub CenterWindow(x,y)
        window.resizeTo x, y
        iLeft = window.screen.availWidth/2 - x/2
        itop = window.screen.availHeight/2 - y/2
        window.moveTo ileft, itop
    End Sub
    
    Sub SendMail()
        SendMailMessage txtFrom.Value, txtTo.Value, txtSubject.Value, txtBody.value ,txtSMTPSERVER.Value, file.Value      
    End Sub
    
    Sub SendMailMessage( sFrom, sTo, sSubject, sBody, SMTPSERVER, File)
        MsgBox "Send with:"& vbCrLf &"From: "& sFrom & vbCrLf & "To: " & sTo & vbCrLf &"Subject: " & sSubject & vbCrLf &"Text Message: " & sBody & vbCrLf & "SMTP SERVER: " & SMTPSERVER & vbCrLf & "Attachment: " & File,64,"Send Email"
        messageHTML="This an example of Signature in HTML Mode sended by hackoo" 
        File = document.getElementById("file").Value 
        
        Set msg = CreateObject("CDO.Message") 
        With msg
            .From = sFrom
            .To = sTo 
            .Subject = sSubject
            .TextBody = sBody 
            .HTMLBody=sBody & vbCrLf & vbCrLf &"<center><font size=4 FACE=Tahoma Color=red>"&messageHTML&"<br><br><img src=[URL unfurl="true"]http://photomaniak.com/upload/out.php/i1102064_IDNlogo.gif>"[/URL] 
            .Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2 
            .Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = SMTPSERVER 
            .Configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25 
            .AddAttachment(File) ' adding Attachment 
            .Configuration.Fields.Update 
            On Error Resume Next
            .Send
            If Err.Number <>0 Then 
                MsgBox Err.Description,16,"Error Sending Mail"
            Else 
                MsgBox "The Mail is sended Sucessfully !",64,"Information" 
            End If
             
        End With
    
    End Sub
    
</script> 
</head> 

<body> 
    
    <label for="from" style="width: 120; textalign: right;">From:</label><input type="text" id="txtFrom" name="from" value="me@here.com"><br /> 
    <label for="to" style="width: 120; textalign: right;">To:</label><input type="text" id="txtTo" name="to" value="you@there.com"><br />
    <label for="subject" style="width: 120; textalign: right;">Subject:</label><input type="text" id="txtSubject" name="subject" value="Default Subject"><br />
    <label for="txtSMTPSERVER" style="width: 120; textalign: right;">SMTP:</label><input type="text" id="txtSMTPSERVER" name="txtSMTPSERVER" value=" Votre Serveur SMTP"><br />
    <label for="file">Pièce-Jointe :</label><br />
    <input type="file" name="file" id="file" /><br>
    <label>Message body:</label><br />
    <textarea id="txtBody" rows="20" cols="45">Enter some text</textarea><br><br>
    <center><input class="btn" type="button" value="Quit" onClick="window.close">
    <input class="btn" type="button" value="Send" onClick="SendMail"> 
</body> 
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top