Solved

How do I schedule an excel file to be sent automatically via email

Posted on 2013-01-16
5
347 Views
Last Modified: 2013-02-16
I would like to automate the sending of an excel spreadsheet via email to be triggered on a schedule defined in windows 7. Is it possible to use the task scheduler? IF so how?
0
Comment
Question by:mbs2000
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:Alex_W
ID: 38783329
This may be of some use:

http://www.outlookforums.com/threads/34063-auto-send-attachment/

I think you may end up with a plug in or 3rd party application.
0
 
LVL 9

Accepted Solution

by:
TazDevil1674 earned 250 total points
ID: 38783367
There are many ways this could be done using either Batch File or VBS.


VBS Example

Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
Set fso = CreateObject("Scripting.FileSystemObject")

SigString = "C:\Users\USER\AppData\Roaming\Microsoft\Signatures\Signature.htm"

If fso.FileExists(SigString) Then
	Signature = GetBoiler(SigString)
Else
	Signature = ""
End If

With mailobj
	'.SentOnBehalfOfName = 
	.To = "alpha@domain.com"
	.CC = "beta@domain.com" & ";" & "charlie@domain.com"
	.Subject = "Automated Report"
	'.Body = "As requested, please see attached..." & vbNewLine & Signature
	.HTMLBody = "<HTML>" & _
        "<p style='font-family:calibri;font-size:14'>" & _
		"As requested, please see attached..." & _
		"<BR><BR>" & Signature & _
		"</HTML>"
	.Attachments.Add "\\unc_server_anme\share\file.pdf"
	.Attachments.Add "D:\files\excel.xls"
	' uncomment .Send to send automatyically - comment out .Display
                .Display
	'.Send
End With

'Clear the memory
Set outobj = Nothing
Set mailobj = Nothing

Function GetBoiler(ByVal sFile ) 'As String) 'As String
'Dick Kusleika
    Dim fso 'As Object
    Dim ts 'As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
End Function

Open in new window


Batch File Example
Set objEmail = CreateObject("CDO.Message")

objEmail.From = "helpdesk@fabrikam.com"
objEmail.To = "administrator@fabrikam.com"
objEmail.Subject = "Server down" 
objEmail.Textbody = "Server1 is no longer accessible over the network."
objEmail.AddAttachment "C:\Scripts\Output.txt"

objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
        "smtpmailer" 
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update

objEmail.Send

Open in new window


Batch file would be good if you may not be logged on or have outlook open...  

You could then set up a scheduled task to run either...
0
 
LVL 8

Assisted Solution

by:d0ughb0y
d0ughb0y earned 250 total points
ID: 38783403
If you're using Outlook, an approach that I have seen in the past (not recently, mind you) is to use an Outlook add-on, like Slipstick. That should be able to do what you're asking, but it is shareware, and ultimately, you'd have to pay for it.

If you're not using Outlook, then you can use the scheduler to send it, but you're going to need to do a little coding, and/or use some tools to get it done. I've done it with Google, for example, by downloading and using SendEmail for Windows, or Blat for Windows.

I've used both, but the one I remember best was SendEmail. The command that you're going to set as your action is going to be something like this. (Remember, I'm using Google as my host here.)
sendemail.exe -f <your email address> -t <the target email address> -u <your subject line> -m <your message> -a <the complete path to the file> -s smtp.gmail.com:587 -xu <your login account - could be the same as your email address> -xp <your account password> -o tls=yes

That's what you'd use. You could put it into a batch file, and then call that from the scheduler. Or you could just use sendemail.exe as the action, and that long string as the optional parameters. Make sure you use the folder where you have the sendemail executable, as the Start In folder.
0
 
LVL 8

Expert Comment

by:d0ughb0y
ID: 38783439
Just wanted to point out that the "Batch file" listed above, isn't a batch file. It's VBS as well. Try typing any of those commands at the C:\ prompt, and see what happens. Heck, try typing them at the PowerShell prompt and see what happens.

That said, that VBS would probably do the job too.
0
 
LVL 9

Expert Comment

by:TazDevil1674
ID: 38783534
@d0ughb0y, thanks for spotting that...  brain not working fully today!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now