Overkill
Hi everyone.. I've been searching a lot but i havent found anything useful so im posting.. -
How do i send an email to xxx@gmail.com along with an attachment from the current directory, all using scripting? Basically i just want to send an email to my own account i.e xxx@gmail.com containing an attached file , using scripting
I need to send it to a real email address , xxx@gmail.com or @hotmail.com etc
Last edited by Overkill (25 Aug 2007 13:35)
----------------------------
#2 25 Aug 2007 14:00
Simon Sheppard
Try the script below - just plug in the ip address of your mail server
Code: Select all
' ---------------------------------------------------------
Sub SendMail( strMailFrom, strMailTo, strMailSubject, strMailBody, strAttachment )
On Error Resume Next
Set oMail = CreateObject("CDO.Message")
oMail.From = strMailFrom
oMail.To = strMailTo
oMail.Subject = strMailSubject
oMail.Textbody = strMailBody
oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.100.100.100"
' use the IP of an internal SMTP relaying server
oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
If strAttachment <> "" Then oMail.AddAttachment strAttachment
oMail.Configuration.Fields.Update
oMail.Send
If Err.Number <> 0 Then
wscript.echo "Could not send email to " & strMailTo & ": " & Err.Number & "-" & Err.Description
End if
set oMail = nothing
End Sub
' -----------------------------------------------
#3 25 Aug 2007 14:57
Overkill
This is my script:
Code: Select all
Sub SendMail( strMailFrom, strMailTo, strMailSubject, strMailBody, strAttachment )
On Error Resume Next
Set oMail = CreateObject("CDO.Message")
oMail.From = ws.ComputerName
oMail.To = "xxx@gmail.com"
oMail.Subject = ws.ComputerName
oMail.Textbody = "Attached"
strAttachment = "c:\text.txt"
oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "http://smtp.gmail.com"
' use the IP of an internal SMTP relaying server
oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
If strAttachment <> "" Then oMail.AddAttachment strAttachment
oMail.Configuration.Fields.Update
oMail.Send
set oMail = nothing
End Sub
' -----------------------------------------------
Oh and i dont need any kind of error reporting, or alerts if it fails
Last edited by Overkill (25 Aug 2007 15:01)
----------------------------
#4 26 Aug 2007 08:39
Overkill
Anyone? Please!
----------------------------
#5 28 Aug 2007 17:41
Overkill
Can anyone help please?
----------------------------
#6 28 Aug 2007 22:00
Simon Sheppard
I think that script is written assuming you have a local email server (MS Exchange) Perhaps something like Blat! will be easier for this https://www.blat.net/
----------------------------
#7 30 Aug 2007 19:19
Overkill
K thanks a lot smile