VB Script to send Outlook 2003 mail to recepient with attachment

G

Guest

I am trying to find the code that will allow me to automatically send and
email a defined receiptent's name with an attachment.

I have been attempting to use the Command-Line options of outlook /c /m
(e-mail address removed) /a c:\temp\xyz.dat.

The switches are not compatiable and result in error.

As it is extremely difficult to find a definitive answer from any source, I
was hoping that any of you kind folk may be able to suggest a work-around, VB
script, etc that can be run on Windows XP.

Thanks
 
S

Sue Mosher [MVP-Outlook]

Set objOL = CreateObject("Outlook.Application")
Set objMail = objOL.CreateItem(0)
With objMail
.Subject = "something"
.To = "name of recipient"
.Attachments.Add "c:\temp\xyz.dat"
.Display
End With
 
G

Guest

Sue,

Thank you - this worked perfectly, however, I am executing the VB script as
a macro from the command-line such that:

c:> c:\progra~1\micros~1\Office11\outlook /autorun SendMail

SendMail macro is defined as:

Sub SendMail()
Set objOL = CreateObject("Outlook.Application")
Set objMail = objOL.CreateItem(0)
With objMail
.Subject = "Test Message via VB"
.To = "name of recipient"
.Attachments.Add "c:\temp\xyz.dat"
.Send
End With
End Sub

The above does not execute automatically, of which I have deduced to the
SendMail macro. When I run the macro separately, a "program is trying to send
mail using Item.Send" dialog box is displayed of which I must manually press
yes for the mail to be send. I would like the VB script (or command line
swicth) to assume I have pressed Yes and send the email.

Thanks is anticipation of your response.

Steve
 
S

Sue Mosher [MVP-Outlook]

Outlook version?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Sue,

Outlook 2003.

Steve

Sue Mosher said:
Outlook version?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

Since you're coding this as a VBA not macro, not VBScript, you can use the
intrinsic Application object that Outlook VBA supports instead of creating a
new Outlook.Application object.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Sue,

Excuse by ignorance but I have little programming understanding. I really
would appreciate if you could spell out exactly what I would need to do.

Thanks, Steve :)
 
S

Sue Mosher [MVP-Outlook]

Replace

Set objOL = CreateObject("Outlook.Application")
Set objMail = objOL.CreateItem(0)

with

Set objMail = Application.CreateItem(0)
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Sue,

Thnak you - the Set objMail = Application.CreateItem(0) automaically sent
the email when the SendMail macro was run from within Outlook 2003.

I still cannot get this macro to be execute from the DOS command line, such
that:

c:\program files\microsoft office\Office11\outlook /autorun SendMail

The "/autorun macroname" switch does not get recognised, although it is
supposed to open Outlook and immediately run the macro specified in
macroname. All that happens is outlook is started, nothing is executed.
Possiblly the /autorun switch does not actually function???

Thanks, Steve
 
S

Sue Mosher [MVP-Outlook]

Sorry, I was focusing on the issue with the security prompt. I've never seen
the /autorun switch work successfully with an Outlook macro.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Michael Bauer

Hi Steve,

this works. Maybe you have to correct the path to OL, and the one for
the attachment, of course. Paths need to be in quotas.

"C:\Programme\Microsoft Office\Office\Outlook.exe" /c ipm.note /m
(e-mail address removed) /a "c:\test.txt"
 
G

Guest

Michael,

Thanks - tried and did not work. error is the "The command line argument is
not valid". Appears the combination of /c & /m with /a does not work.

I am running Outlook 2003 on Windows XP Pro.

Steve
 
G

Guest

Michael,

The full string is as follows, which I run from c:\program files\microsoft
office\office10:

"c:\program files\microsoft office\office10\outlook" /c ipm.note /m
(e-mail address removed) /a "c:\temp\SendMail.xyz"

I am running Outlook 2002 on MS Windows XP Home at home, and also testing on
a Windows XP Pro with Outlook 2003.

Steve
 
M

Michael Bauer

Hi Steve,

indeed it doesn´t work. You can use /c together with /m *or* with /a,
but not with both of them.
 
J

jpfumk

How do you get around the security warning
"A program is trying to automatically send e-mail on you behalf"

with outlook 2000

Here is what I have
---------------------------------------------

Sub SendMail()
Set objMail = Application.CreateItem(0)

With objMail
.Subject = "Test Message via VB"
.To = "sendor"
.Body = "This is the body"
'.Attachments.Add "e:\wayne.doc"
.Send
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top