#1 25 Aug 2007 13:31

Overkill
Member
Registered: 25 Aug 2007
Posts: 6

Send a live email with attachment

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)

Offline

#2 25 Aug 2007 14:00

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 763
Website

Re: Send a live email with attachment

Try the script below - just plug in the ip address of your mail server

' ---------------------------------------------------------
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
' -----------------------------------------------

Offline

#3 25 Aug 2007 14:57

Overkill
Member
Registered: 25 Aug 2007
Posts: 6

Re: Send a live email with attachment

This is my script:

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
' -----------------------------------------------

I tried it, it executes without any kind of error but it doesnt send an email.. Im sorry i have no experience with this sort of thing in windows script, so i dont know whats happening

Oh and i dont need any kind of error reporting, or alerts if it fails

Last edited by Overkill (25 Aug 2007 15:01)

Offline

#4 26 Aug 2007 08:39

Overkill
Member
Registered: 25 Aug 2007
Posts: 6

Re: Send a live email with attachment

Anyone? Please!

Offline

#5 28 Aug 2007 17:41

Overkill
Member
Registered: 25 Aug 2007
Posts: 6

Re: Send a live email with attachment

Can anyone help please?

Offline

#6 28 Aug 2007 22:00

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 763
Website

Re: Send a live email with attachment

I think that script is written assuming you have a local email server (MS Exchange)  Perhaps something like Blat! will be easier for this http://www.blat.net/

Offline

#7 30 Aug 2007 19:19

Overkill
Member
Registered: 25 Aug 2007
Posts: 6

Re: Send a live email with attachment

K thanks a lot smile

Offline

Board footer

Powered by FluxBB