By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,087 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,087 IT Pros & Developers. It's quick & easy.

Cannot Send Mail Through Outlook without Outlook Open

P: n/a
I'm trying to send using outlook but I get an error on the directcast line
if I don't have outlook open. Works fine if it is open. What do I need to
do to be able to send without having outlook open? Thanks

Dim objOutlook As New Outlook.Application

Dim objMail As Outlook._MailItem =
DirectCast(objOutlook.CreateItem(Outlook.OlItemTyp e.olMailItem),
Outlook._MailItem)

Dim mSubject As String

Dim mBody As String

mSubject = client & " - " & fDescription.Text

mBody = ControlChars.CrLf & "file:" & fFilename.Text & ControlChars.CrLf &
ControlChars.CrLf &

With objMail

..BodyFormat = Outlook.OlBodyFormat.olFormatRichText

..To = us**@domain.com

..Subject = mSubject

..Body = mBody

..Send()

End With

objMail = Nothing

objOutlook = Nothing
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Tue, 21 Sep 2004 19:27:17 -0500, "Barkster" <bd***@hotmail.com> wrote:

I'm trying to send using outlook but I get an error on the directcast line
if I don't have outlook open. Works fine if it is open. What do I need to
do to be able to send without having outlook open? Thanks

Dim objOutlook As New Outlook.Application


Try the following instead of the above line of code:

Dim objOutlook As Outlook._Application
objOutlook = New Outlook.Application()
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #2

P: n/a
will do, thanks

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:49********************************@4ax.com...
On Tue, 21 Sep 2004 19:27:17 -0500, "Barkster" <bd***@hotmail.com> wrote:

I'm trying to send using outlook but I get an error on the directcast line if I don't have outlook open. Works fine if it is open. What do I need to do to be able to send without having outlook open? Thanks

Dim objOutlook As New Outlook.Application


Try the following instead of the above line of code:

Dim objOutlook As Outlook._Application
objOutlook = New Outlook.Application()
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 21 '05 #3

P: n/a
Tried that and got the same error, stops on line
Dim objMail As Outlook._MailItem =
DirectCast(objOutlook.CreateItem(Outlook.OlItemTyp e.olMailItem),
Outlook._MailItem)
with the following error

An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in ScanMail.exe

"B-Dog" <bd***@hotmail.com> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
will do, thanks

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:49********************************@4ax.com...
On Tue, 21 Sep 2004 19:27:17 -0500, "Barkster" <bd***@hotmail.com> wrote:
I'm trying to send using outlook but I get an error on the directcast line
if I don't have outlook open. Works fine if it is open. What do I

need to
do to be able to send without having outlook open? Thanks

Dim objOutlook As New Outlook.Application


Try the following instead of the above line of code:

Dim objOutlook As Outlook._Application
objOutlook = New Outlook.Application()
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)


Nov 21 '05 #4

P: n/a
On Wed, 22 Sep 2004 10:44:03 -0500, "B-Dog" <bd***@hotmail.com> wrote:

Tried that and got the same error, stops on line
Dim objMail As Outlook._MailItem =
DirectCast(objOutlook.CreateItem(Outlook.OlItemTyp e.olMailItem),
Outlook._MailItem)


with the following error

An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in ScanMail.exe

What is ScanMail? Is it anti-virus software for Exchange?
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #5

P: n/a
Didn't notice that, I'll have to look into it. Thanks

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:li********************************@4ax.com...
On Wed, 22 Sep 2004 10:44:03 -0500, "B-Dog" <bd***@hotmail.com> wrote:

Tried that and got the same error, stops on line
Dim objMail As Outlook._MailItem =
DirectCast(objOutlook.CreateItem(Outlook.OlItemTyp e.olMailItem),
Outlook._MailItem)


with the following error

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in ScanMail.exe

What is ScanMail? Is it anti-virus software for Exchange?
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 21 '05 #6

P: n/a
Figured it out, wasn't logining in using using mapi and profile

Try

'now need to send to Jack from list

Dim objOutlook As Outlook._Application

Dim OLNameSpace As Outlook.NameSpace

Dim objMail As Outlook.MailItem

Dim mSubject As String

Dim mBody As String

objOutlook = New Outlook.Application

OLNameSpace = objOutlook.GetNamespace("MAPI")

OLNameSpace.Logon()

objMail = CType(objOutlook.CreateItem(Outlook.OlItemType.olM ailItem),
Outlook.MailItem)

mBody = ""

mSubject = "Daily Attendance"

Dim icount As Integer

For icount = 0 To lbAttend.Items.Count - 1

mBody &= CType(CType(lbAttend.Items(icount), DataRowView)("Description"),
String) & ControlChars.CrLf

Next

With objMail

..BodyFormat = Outlook.OlBodyFormat.olFormatRichText

..To = "ba*****@domain.com"

..Subject = mSubject

..Body = mBody

..Send()

End With

OLNameSpace.Logoff()

OLNameSpace = Nothing

objMail = Nothing

objOutlook = Nothing

Catch ex As Exception

MsgBox(ex)

End Try

End Sub
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.