From: Boon on
Hello,

I have been able to write a code that will send email via outlook. The next
improvement I would like to do is to select the account for outgoing email.
On my outlook I have 2 email accounts. (My personal account which is the
default. Another account is the shared account and it is the one I want my
VBA code using it.)

I found that there is a function Sendusingaccount and don't know how to use
it.

I would appreciate your help.

thanks so much,
Boon


From: Daniel Pineault on
You should ask this question in an Outlook Forum. You are more likely to get
a quicker answer.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Boon" wrote:

> Hello,
>
> I have been able to write a code that will send email via outlook. The next
> improvement I would like to do is to select the account for outgoing email.
> On my outlook I have 2 email accounts. (My personal account which is the
> default. Another account is the shared account and it is the one I want my
> VBA code using it.)
>
> I found that there is a function Sendusingaccount and don't know how to use
> it.
>
> I would appreciate your help.
>
> thanks so much,
> Boon
>
>
> .
>
From: Mark Andrews on
Boon,

I wrote the following code (no guarantees, I'm testing it out with a client
in Singapore right now).

The top portion tries to match the outlook account (I think I found a code
example on microsoft's site somewhere).

HTH,
Mark Andrews
RPT Software
http://www.rptsoftware.com
http://www.donationmanagementsoftware.com


Public Sub CreateEmail(strFrom As String, strTo As String, strCC As String,
strBCC As String, strSubject As String, strTextOrHTML As String, strBodyText
As String, strBodyHTML As String)
On Error GoTo Err_CreateEmail
Dim OlApp As Outlook.Application
Dim olAccounts As Outlook.Accounts
Dim olAccount As Outlook.Account
Dim olAccountTemp As Outlook.Account
Dim olMail As MailItem
Dim FoundAccount As Boolean

Set OlApp = New Outlook.Application
FoundAccount = False

'loop through and find Outlook account based on from email address
Set olAccounts = OlApp.Application.Session.Accounts
For Each olAccountTemp In olAccounts
If (olAccountTemp.smtpAddress = strFrom) Then
Set olAccount = olAccountTemp
FoundAccount = True
Exit For
End If
Next


If (FoundAccount) Then
Set olMail = OlApp.CreateItem(olMailItem)
With olMail
.SendUsingAccount = olAccount
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = strSubject
If (strTextOrHTML = "HTML") Then
.BodyFormat = olFormatHTML
.Body = strBodyText
.HTMLBody = strBodyHTML
Else
.BodyFormat = olFormatPlain
.Body = strBodyText
End If
' .Attachments.Add filename
.Display
End With
Else
MsgBox "Could not find the appropriate Outlook account for email
address: " & strFrom & ". Contact RPT Software for assistance if needed.",
vbOKOnly, "Outlook error retrieving SMTP account"
End If

Exit_CreateEmail:
Set olMail = Nothing
Set olAccount = Nothing
Set OlApp = Nothing
Exit Sub

Err_CreateEmail:
MsgBox Err.Description
Resume Exit_CreateEmail
End Sub


"Boon" <boonyawat.la-ongthong(a)cnh.com> wrote in message
news:uN4LI383KHA.4336(a)TK2MSFTNGP04.phx.gbl...
> Hello,
>
> I have been able to write a code that will send email via outlook. The
> next improvement I would like to do is to select the account for outgoing
> email. On my outlook I have 2 email accounts. (My personal account which
> is the default. Another account is the shared account and it is the one I
> want my VBA code using it.)
>
> I found that there is a function Sendusingaccount and don't know how to
> use it.
>
> I would appreciate your help.
>
> thanks so much,
> Boon
>
>
From: Lee Taylor-Vaughan on
Mark, You rock! works great!
thanks a ton buddy.. i've been trying to figure this out for ages!!!
Lee

"Mark Andrews" <mandrews___NOSPAM___(a)rptsoftware.com> wrote in message
news:Ojdw5J$3KHA.1452(a)TK2MSFTNGP06.phx.gbl...
> Boon,
>
> I wrote the following code (no guarantees, I'm testing it out with a
> client in Singapore right now).
>
> The top portion tries to match the outlook account (I think I found a code
> example on microsoft's site somewhere).
>
> HTH,
> Mark Andrews
> RPT Software
> http://www.rptsoftware.com
> http://www.donationmanagementsoftware.com
>
>
> Public Sub CreateEmail(strFrom As String, strTo As String, strCC As
> String, strBCC As String, strSubject As String, strTextOrHTML As String,
> strBodyText As String, strBodyHTML As String)
> On Error GoTo Err_CreateEmail
> Dim OlApp As Outlook.Application
> Dim olAccounts As Outlook.Accounts
> Dim olAccount As Outlook.Account
> Dim olAccountTemp As Outlook.Account
> Dim olMail As MailItem
> Dim FoundAccount As Boolean
>
> Set OlApp = New Outlook.Application
> FoundAccount = False
>
> 'loop through and find Outlook account based on from email address
> Set olAccounts = OlApp.Application.Session.Accounts
> For Each olAccountTemp In olAccounts
> If (olAccountTemp.smtpAddress = strFrom) Then
> Set olAccount = olAccountTemp
> FoundAccount = True
> Exit For
> End If
> Next
>
>
> If (FoundAccount) Then
> Set olMail = OlApp.CreateItem(olMailItem)
> With olMail
> .SendUsingAccount = olAccount
> .To = strTo
> .CC = strCC
> .BCC = strBCC
> .Subject = strSubject
> If (strTextOrHTML = "HTML") Then
> .BodyFormat = olFormatHTML
> .Body = strBodyText
> .HTMLBody = strBodyHTML
> Else
> .BodyFormat = olFormatPlain
> .Body = strBodyText
> End If
> ' .Attachments.Add filename
> .Display
> End With
> Else
> MsgBox "Could not find the appropriate Outlook account for email
> address: " & strFrom & ". Contact RPT Software for assistance if
> needed.", vbOKOnly, "Outlook error retrieving SMTP account"
> End If
>
> Exit_CreateEmail:
> Set olMail = Nothing
> Set olAccount = Nothing
> Set OlApp = Nothing
> Exit Sub
>
> Err_CreateEmail:
> MsgBox Err.Description
> Resume Exit_CreateEmail
> End Sub
>
>
> "Boon" <boonyawat.la-ongthong(a)cnh.com> wrote in message
> news:uN4LI383KHA.4336(a)TK2MSFTNGP04.phx.gbl...
>> Hello,
>>
>> I have been able to write a code that will send email via outlook. The
>> next improvement I would like to do is to select the account for outgoing
>> email. On my outlook I have 2 email accounts. (My personal account which
>> is the default. Another account is the shared account and it is the one I
>> want my VBA code using it.)
>>
>> I found that there is a function Sendusingaccount and don't know how to
>> use it.
>>
>> I would appreciate your help.
>>
>> thanks so much,
>> Boon
>>
>>

From: Lee Taylor-Vaughan on
one question.
How can i populate a combo box with the list of outlook SMTP accounts on a
form?
thanks
lee



"Mark Andrews" <mandrews___NOSPAM___(a)rptsoftware.com> wrote in message
news:Ojdw5J$3KHA.1452(a)TK2MSFTNGP06.phx.gbl...
> Boon,
>
> I wrote the following code (no guarantees, I'm testing it out with a
> client in Singapore right now).
>
> The top portion tries to match the outlook account (I think I found a code
> example on microsoft's site somewhere).
>
> HTH,
> Mark Andrews
> RPT Software
> http://www.rptsoftware.com
> http://www.donationmanagementsoftware.com
>
>
> Public Sub CreateEmail(strFrom As String, strTo As String, strCC As
> String, strBCC As String, strSubject As String, strTextOrHTML As String,
> strBodyText As String, strBodyHTML As String)
> On Error GoTo Err_CreateEmail
> Dim OlApp As Outlook.Application
> Dim olAccounts As Outlook.Accounts
> Dim olAccount As Outlook.Account
> Dim olAccountTemp As Outlook.Account
> Dim olMail As MailItem
> Dim FoundAccount As Boolean
>
> Set OlApp = New Outlook.Application
> FoundAccount = False
>
> 'loop through and find Outlook account based on from email address
> Set olAccounts = OlApp.Application.Session.Accounts
> For Each olAccountTemp In olAccounts
> If (olAccountTemp.smtpAddress = strFrom) Then
> Set olAccount = olAccountTemp
> FoundAccount = True
> Exit For
> End If
> Next
>
>
> If (FoundAccount) Then
> Set olMail = OlApp.CreateItem(olMailItem)
> With olMail
> .SendUsingAccount = olAccount
> .To = strTo
> .CC = strCC
> .BCC = strBCC
> .Subject = strSubject
> If (strTextOrHTML = "HTML") Then
> .BodyFormat = olFormatHTML
> .Body = strBodyText
> .HTMLBody = strBodyHTML
> Else
> .BodyFormat = olFormatPlain
> .Body = strBodyText
> End If
> ' .Attachments.Add filename
> .Display
> End With
> Else
> MsgBox "Could not find the appropriate Outlook account for email
> address: " & strFrom & ". Contact RPT Software for assistance if
> needed.", vbOKOnly, "Outlook error retrieving SMTP account"
> End If
>
> Exit_CreateEmail:
> Set olMail = Nothing
> Set olAccount = Nothing
> Set OlApp = Nothing
> Exit Sub
>
> Err_CreateEmail:
> MsgBox Err.Description
> Resume Exit_CreateEmail
> End Sub
>
>
> "Boon" <boonyawat.la-ongthong(a)cnh.com> wrote in message
> news:uN4LI383KHA.4336(a)TK2MSFTNGP04.phx.gbl...
>> Hello,
>>
>> I have been able to write a code that will send email via outlook. The
>> next improvement I would like to do is to select the account for outgoing
>> email. On my outlook I have 2 email accounts. (My personal account which
>> is the default. Another account is the shared account and it is the one I
>> want my VBA code using it.)
>>
>> I found that there is a function Sendusingaccount and don't know how to
>> use it.
>>
>> I would appreciate your help.
>>
>> thanks so much,
>> Boon
>>
>>