Sending Mail programatically

J

JonWayne

I am using the following snippet of code to send myself a message with
outlook 2003. The message shows up in the Outbox and then eventually
disappears, but never show up in my inbox. Anybody know why it doesnt get
sent? Also, can someone explain what is entered as the profile - the first
argument to the Logon method

Sub SendWithOutlook03()
Dim m As Outlook.MailItem, atch As Outlook.Attachment, Fldr As
Outlook.MAPIFolder, ns As Outlook.NameSpace
Dim App As Outlook.Application
Dim fso As FileSystemObject, TS As Scripting.TextStream, RecFile As
Scripting.File, WacFile As Scripting.File
Dim sBodyText$, AttachFile$

On Error Resume Next
Set App = GetObject(, "Outlook.Application")
If App Is Nothing Then Set App = CreateObject("Outlook.Application")
Set ns = App.GetNamespace("MAPI")
ns.Logon
Set Fldr = ns.GetDefaultFolder(olFolderOutbox)
Set m = Fldr.Items.Add(olMailItem)

sBodyText = CreateHTMLTable
'creates a block of html codes defining a table of values
AttachFile = "C:\Working\Access\Wayne.mdb"

With m
Set atch = .Attachments.Add(AttachFile)
.Recipients.Add ("(e-mail address removed)")
MsgBox .SenderEmailAddress & ", " & .SenderEmailType & ", " &
..SenderName 'this line comes up blank for each property, why?
.Body = sBodyText
.Subject = " WAC"
.BodyFormat = olFormatHTML
.Send
End With
End Sub
 
K

Ken Slovak - [MVP - Outlook]

Where is that code running? From Outlook or somewhere else?

You usually don't need to logon at all if Outlook is running already, you
just piggy-back on the existing Outlook session.

Your message box is in error because you aren't getting a Recipient object,
which is what has the properties you are asking for. You should also try
resolving the Recipient, you can do that using Recipients.ResolveAll.

If the message is actually being sent out from Outlook I have no idea what
is happening to it once it leaves.

BTW, programming questions like this are much better in a programming group
where they won't get lost and where the developers hang out. You should post
things like this in microsoft.public.outlook.program_vba.
 

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