Hi all,

I use the following code to send an email from my application:
vb Code:
  1. Public Function olk_SendMail(sTo As String, sSubject As String, sMessage As String, Optional ByVal blnSend As Boolean = True)
  2.     On Error GoTo Err_Trap
  3.     Dim objOutlook As Outlook.Application
  4.     Dim objMailItem As Outlook.MailItem
  5.     Set objOutlook = New Outlook.Application
  6.     Set objMailItem = objOutlook.CreateItem(olMailItem)
  7.  
  8.     With objMailItem
  9.         .To = sTo
  10.         .Subject = sSubject
  11.         .body = sMessage
  12.         If blnSend Then
  13.             .send
  14.         Else
  15.             .Save
  16.         End If
  17.     End With
  18.     Set objMailItem = Nothing
  19.     Set objOutlook = Nothing
  20.     Exit Function
  21.  
  22. Err_Trap:
  23.     Debug.Print Err.Number & " " & Err.Description
  24. End Function
It works fine. I am executing this code from Excel. My problems are:

1. The code prompts/warns the user that,

"A program is trying to automatically send e-mail on your behalf. Do you want to allow this?"

If the user clicks "Yes" then the mail sent successfully. No issues.

How to send mail without confirmation?

2. It sends the mail using Outlook with its default account. I mean, I have configured two email accounts in my outlook. One is default.

How can I send email using outlook from the email account which is not default?

Thanks in advance.