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!

Sending email attachment

Status
Not open for further replies.

i_malc

Technical User
Apr 19, 2017
3
ES
Can somebody please advise me on sending an email attachment using VBs. I've got the following code which I cant get to work. I think it might be that it needs a username and password inserting for it to send via the 1 and 1 SMTP server account. but I don't know where it needs inserting.
DIM fso
Set fso=CreateObject("Scripting.FilesystemObject")
On Error Resume Next
fso.CopyFile "D:\Backup docs1\Zip.zip"
'Wscript.Echo "File copy complete."
strSMTPFrom = "backups@XXXXXX.co.uk"
strSMTPTo = "i_MALC@XXXXXXX.co.uk"
strSMTPRelay = "auth.smtp.1and1.co.uk"
strTextBody = "Backup done vbs"
strSubject = "VBS Script"
strAddAttachment "D:\Backup docs1\Zip.zip"
Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item(" = 2
oMessage.Configuration.Fields.Item(" = strSMTPRelay
oMessage.Configuration.Fields.Item(" = 465
oMessage.Configuration.Fields.Update
oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
'oMessage.AddAttachment strADDAttachment

oMessage.Send
'Wscript.Echo "Email sent."
Const TIMEOUT = 10
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Popup "Email sent" , TIMEOUT
 
Bah, site sort of ate the post, below should be better:

Code:
oMessage.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")[/URL] = 1 
oMessage.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusername")[/URL] ="mail@yourdomain.com"
oMessage.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendpassword")[/URL] ="yourpassword"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top