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!

script that sends email w attachment automatically 2

Status
Not open for further replies.

jjaanus

IS-IT--Management
Dec 12, 2003
9
EE
does anyone knows or has script example, how outlook sends automatycally email with attachment in specific time?
 
Try this:
Dim objOutl
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
'comment the next line if you do not want to see the outlook window
objMailItem.Display
strEmailAddr = "me.me@you.com"
objMailItem.Recipients.Add strEmailAddr
objMailItem.Body = "Hi"
objMailItem.Attachments.Add "file.xml"
objMailItem.Send
Set objMailItem = nothing
Set objOutl = nothing
 
tnx it works

there is one little problem. when i run the macro(in outlook 2000,and there is exchange server 2000), there appear popup window and asks "a program is trying to access e-mail addresses you have stored in Outlook. do you want to allow this?" and "A program is trying to send e-mail on your behalf.do you want to allow this?"

does anybody can tell how to configure exchange 2000 server that these windows appear?
or is it possible to add some script that ingnore these messages?
sendind mail should work automatically.

Jaanus
 
do you have outlook open on the server you are running the script on, or just installed?
 
its a security feature of outlook!!! nice, good i suppose, unless you want to supress it!!!

i get round it by sending email via an smtp server instead, taht way you dont have to concern yourself with outlook
 
there is no matter if the outlook is open during running macro or not open. same popup appears.

to mrmovie: i use also smtp server. friend said that there have to be possibility to uncheck some.. that allow internet....i dont remember exactly. but he didnt know where it have to be configure.

 
'smtp
'notify someone that this has been run
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim strSubject
Dim strFrom
Dim strAttachment

set imsg = createobject("cdo.message")
set iconf = createobject("cdo.configuration")

Set Flds = iConf.Fields
With Flds
.Item(" = 2
.Item(" = "ball.blaa.net" 'ToDo: Type a valid SMTP server name.
.Update
End With

strHTML = &quot;<HTML>&quot;
strHTML = strHTML & &quot;<HEAD>&quot;
strHTML = strHTML & &quot;<BODY>&quot;
strHTML = strHTML & &quot;<b> ulsmsreinstall</b></br>&quot;
strHTML = strHTML & &quot;<hr>&quot;
strHTML = strHTML & &quot;...</BR>&quot;
strHTML = strHTML & &quot;</BODY>&quot;
strHTML = strHTML & &quot;</HTML>&quot;
strSubject = waspMach.ComputerName & &quot;, ulssmsreinstall&quot;
strFrom = waspMach.ComputerName & &quot;@abc.com&quot;

With iMsg
Set .Configuration = iConf
.To = &quot;X-LAB@abc.com&quot;
.From = strFrom
.Subject = strSubject
.HTMLBody = strHTML
.Send
End With

Set iMsg = Nothing
Set iConf = Nothing
 
you need to type in the fqn nme of your smtp server where it says &quot;ball.blaa.net&quot;
 
Referring back to the script from RalphTrent, I added a couple of Shell.Sendkeys "^~" between each line of his code after the SetObjMailItem line. his effectively kills the popups and executes without the user seeing anything.
 
I have this working down to getting rid of the popups ( do I really want to send this e-mail). I must be doing something wrong in tying to get the Shell.Sendkeys "^~" to work. Ideas please. Or is them some setting that can be turned off.

Thanks much! - Larry
 
sendkeys is pretty flak-eee to say the least.
do you really not have an SMTP server around? perhaps a IIS server that is running it?

if not then try sendkeys({ENTER})
 
Well - now my lack of knowledge will show. In this case I am just a user trying to send txt files from Outlook 2002 automatically and really do not know what a SMPT server is. All I have or can use is the Outlook. I tried the send keys by placing (sendkeys "enter") in vaious places in the code but either get the same security problem or some lock-up. The idea and concept is just so perfect. Just need to get this one thing to work.


Thanks, Larry
 
ok test this from a blank vbscript file

Msgbox "hello world"
WshShell.SendKeys({ENTER})

just to test your sendkeys entry

or post all your code and we can have a look at it.

how do you declare the WshShell???
 
Think its time to hide behide a tree as I know bits and piecss but am basically missing the curve!

What is WshShell, please?

Here is he code from back in Dec with just a bit of touchup. I just can't get rid of the blanky blank popup!

Sub SendMyFile()

Dim objOutl
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
'comment the next line if you do not want to see the outlook window
objMailItem.Display
strEmailAddr = "lt9165@sbc.com"
'SendKeys "^~"
objMailItem.Recipients.Add strEmailAddr
SendKeys "ENTER"
'SendKeys "^~"
'SendKeys "^~"
objMailItem.Body = "Hifrom the e-mailbody "
objMailItem.Attachments.Add "c:\my documents\test.xls"
'SendKeys "^~"
objMailItem.Send
Set objMailItem = Nothing
Set objOutl = Nothing
SendKeys "^~"
SendKeys "^~"
End Sub
 
You have to instantiate the WshShell object prior to use it:
Set WshShell = CreateObject("WScript.Shell")
and then you can do this:
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "^~"

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
alright Larry, here it is a SMTP or Simple Mail Transfer Protocol server is exactly like it sounds, most xp, 2000, 2003 servers had them installed are are an option. These servers usually run on port 25, unless configured otherwise,
plus the 2 configuration fields are needed to send all the required information. so what newcoder54 said was correct, you just need a easier example so hear it is.
Code:
dim iconf : set iconf = createobject("cdo.configuration")
                        
                       dim Flds : Set Flds = iConf.Fields' get field object
dim Ws : Set Ws = CreateObject("Wscript.Shell")
dim compn : compn = Ws.ComputerName' place computer name in variable
                        With Flds'use field object
                            .Item'declare item #1("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusin...;)[/URL] = 2
                            .Item#2("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserv...;)[/URL] = "smtp."& compn &".com" 'ToDo: Type a valid SMTP server ext ie .net .biz .us ....
                            .Update
                        End With

cheers

Phalanx1
 
This one might be easier for you to understand as it has been fully commented. Save the following to a text file and give it an extension of .VBS.

You can edit it with notepad and read the comments which all begin with an apastrophe.

You will need to change just a few lines. You need to put in your domain name, who you want the message sent to, the IP address of your SMTP server and you will need to edit the message body and attachment info. Should all be easy enough to follow.

For your SMTP server, take a look in the properties of your Outlook Email account. If you use POP mail, enter the Outgoing SMTP server name instead of entering an IP address. If you are using an Exchange server, you could try entering that name. You may need to speak to your network admin to allow you to relay to the server.

'==========================================================================
'
' VBScript Source File --
'
' NAME: NotifyReboot.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: ' DATE : 02/13/2003
'
' COMMENT:
'
' This script can be added to a machines startup script in Group Policy to notify
' an e-mail address that the machine has restarted.
'
' You must customize the entries for oDomain, oMyIP and oTo with the proper company information.
' Items to customize are on lines 29, 31 and 33.
'=====================================

Dim oName, ODomain, oMyIP, oTo

' Get the computer name
Set WshNetwork = CreateObject("WScript.Network")
oName = WshNetwork.ComputerName

' Set the company specific information

' Company Internet Domain Name
ODomain = "thespidersparlor.com"
' Set the SMTP server IP
oMyIP = "68.6.19.4"
' Where do you want the message to be delivered
oTo = "markdmac@thespidersparlor.com"


' Set the visual basic constants as they do not exist within VBScript.
' Do not set your smtp server information here.
Const cdoSendUsingMethod = " _
cdoSendUsingPort = 2, _
cdoSMTPServer = "
'// 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 = oName & "@" & oDomain
.Subject = "Server Reboot"
.TextBody = "Server " & oName & "at company " & ODomain & " was restarted " & now
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. Please let me know if it was.

Regards,

Mark
 
This sends email with outlook using MAPI.
Enjoy Bob

Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
ToAddress = "ANDREAS.BURKART@email.COM"
MessageSubject = "Reader Service Leads"
MessageBody = "Here are your leads for 03-10-2004"
MessageAttachment = "Y:\folder\folder\file.CSV"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send
 
Well - I have plenty of material to digest as my available bit of time allows - thanks a bunch for all the help!!

Next gizmo needed: How do I run a Outlook script from Excel or Access?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top