send mail in Outlook specify sending account

Hi,
I have an exe which sends mails out from Outlook(2003) and VB>net 2005
I see there is a property SendUsingAccount.
i would like to specify when sending mail which account it must use to send the mail out on.
Does anyone have a simple sample please

thanks
LVL 4
CraigLazarAsked:
Who is Participating?
 
David LeeConnect With a Mentor Commented:
Hi, CraigLazar.

SendUsingAccount isn't available in Outlook 2003.  It was introduced in Outlook 2007.  With Outlook 2003 the way to send through an account is to simulate clicking on the buttons in the interface.
0
 
CraigLazarAuthor Commented:
Hi BlueDevilFan
ok do u have a sample if i then used Outlook 2007 instead then?
thanks
0
 
David LeeCommented:
This example is directly from Outlook's online help.
Sub SendUsingAccount()
    Dim oAccount As Outlook.account
    For Each oAccount In Application.Session.Accounts
        If oAccount.AccountType = olPop3 Then
            Dim oMail As Outlook.MailItem
            Set oMail = Application.CreateItem(olMailItem)
            oMail.Subject = "Sent using POP3 Account"
            oMail.Recipients.Add ("someone@example.com")
            oMail.Recipients.ResolveAll
            oMail.SendUsingAccount = oAccount
            oMail.Send
        End If
    Next
End Sub

Open in new window

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
CraigLazarAuthor Commented:
h,
one of my accounts isseup usin exchange server, will this still work then?
 
thanks
0
 
David LeeCommented:
The code shows sending a message via a POP account.  It's just an example though.  You can use any account you want.  The key point is to select the account you want to use, then set SendUsingAccount to that account object.  You can select the account by name, by type, etc.
0
 
CodeCruiserConnect With a Mentor Commented:
I use the From property of the MailMessage through Interop to send email through a different address. For any of these techniques to work, the user whose credentials are being used to send the message (in my case its logged in user) must have SendAs permission on the Exchange Server for the other user.
0
 
CraigLazarAuthor Commented:
Hi guys
thank for the help.
I landed up using the .net mailer to send out the mail much easier.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.