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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to autocreate an Email with attachment from HTML

Status
Not open for further replies.

ThorO

Programmer
Sep 28, 2002
20
NO
I try to figure out how to start the mailclient and automatically set an attachment in the mail from a WEB page (HTA). I have tested with mailto, using &attachment="c:\test.txt", but that does not seam to work on XP (but ok on 2000). Clients are always IE.

I just want to open the mailclient on the users PC (Outlook or Outlook express..MUST work on both) and include a pdf file. No adress, subject or anything else is required. No server side prosessing availble, so it must work on the client with e.g. a script.

Any suggestions from the bright guys out there??? Thanks in advance

 
For security reasons Outlook will not let you do this, it falls under the role of a virus.

What you need to do is use CDO to create and send the email. It is simple enough.

Code:
'==========================================================================
' NAME: SendEmail.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 4/23/2004
'
' COMMENT: 
' You must customize the entries for oFrom, oTo and oMyIP with the proper company information.
'=====================================
On Error Resume Next 
Dim oFrom, oMyIP, oTo
Const ForReading = 1

' Set the visual basic constants as they do not exist within VBScript.
' Do not set your smtp server information here.
Const cdoSendUsingMethod = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing",[/URL] _
cdoSendUsingPort = 2, _
cdoSMTPServer = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver"[/URL]

'*************************************************
' Set the company specific information
'*************************************************
' Destination Email Address
oTo = "destination@yourcopany.com"
' Who should the sender be? Email Address
oFrom = "me@mycompany.com"
' Set the SMTP server IP 
oMyIP = "192.168.0.1" 

'Create the CDO connections.
Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

'SMTP server configuration.
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort

'// Set the SMTP server address here.
.Item(cdoSMTPServer) = oMyIP
.Update
End With

'Set the message properties.
With iMsg
Set .Configuration = iConf
.To = oTo
.From = oFrom
.Subject = "A Message For You"
.TextBody = "<html><body><h1>Hi</h1></body></html>"
End With

'An attachment can be included.
'iMsg.AddAttachment = "C:\Attachment.txt"

'Send the message.
iMsg.Send 

MsgBox "Done"

I hope you find this post helpful.

Regards,

Mark
 
Wow...thanks Mark...:) This seams to solve my needs and is quite easy to implement too

Thanks again and have a great day

Thor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top