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

Automatic outgoing email. 1

Status
Not open for further replies.

Barneye

MIS
Mar 5, 2002
68
US
I need to send an automatic email with an attachment each day at a specified time. I also need the attachment to be grabbed from a location on my network each as it changes daily. Can I do this with exchange? I am also using outlook 2003 as well.

Thanks!
 
Try this as a VBS script and schedule it to run when you want it to.

Call the function with sSubject as the Email subject and sPathfile as the attachment that you want to send. To add more attachments, just add ".AddAttachment " again with the path to whatever file you want to add. You will have to do some extra work if the filename is constantly changing unless it a predictable pattern like a date.

Function MailScript(sSubject,sPathfile)

Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim strSmartHost
Dim strMessageBody

Const cdoSendUsingPort = 2
StrSmartHost = "mail.server.com"

set iMsg = CreateObject("CDO.Message")
set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

' set the CDOSYS configuration fields to use port 25 on the SMTP server

With Flds
.Item(" = cdoSendUsingPort
.Item(" = strSmartHost
.Item(" = 100
.Update
End With

' apply the settings to the message
With iMsg
Set .Configuration = iConf
.To = "To address"
.From = "From Address"
.Subject = sSubject
.TextBody = "Body of Email"
.AddAttachment sPathFile
.Send
End With

' cleanup of variables
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing

End Function ' MailScript





Brent
Systems Engineer / Consultant
CCNP
 
Hi!

OK I have tried to get this working but I am not getting anything. I can execute the script with no errors, but I don't recieve an email to the test account.


Here is the script with my info. Am I doing this right? I don't have a lot of experience with VB script.



Function MailScript(sSubject,sPathfile)

Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim strSmartHost
Dim strMessageBody

Const cdoSendUsingPort = 25
StrSmartHost = "mail.irvine.local"

set iMsg = CreateObject("CDO.Message")
set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

' set the CDOSYS configuration fields to use port 25 on the SMTP server

With Flds
.Item(" = cdoSendUsingPort
.Item(" = strSmartHost
.Item(" = 100
.Update
End With

' apply the settings to the message
With iMsg
Set .Configuration = iConf
.To = "pendarus@mindspring.com"
.From = "barneye@inductor.com"
.Subject = "test"
.TextBody = "test"
.AddAttachment "U:\Invsum\Parthunter\inductors_same_day.xls"
.Send
End With

' cleanup of variables
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing

End Function ' MailScript


Thanks!
 
It looks like you got it up right. I always have the To: and From: with the same domain as the mail server. You might be blocked for SMTP relay. Setup Outlook Express with these settings and try and email back out. See if you get a bounced message for SMTP relay or for DNS reverse lookup.

I think there is a way to force login from the script. I will look into it and get back to you. Let me know how the OE test goes.




Brent
Systems Engineer / Consultant
CCNP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top