Public Sub SendUsingPOP3()
Dim myMailItem As Outlook.MailItem
Dim colAccounts As Outlook.Accounts
Dim oNS As Outlook.NameSpace
Dim oAccount As Outlook.Account
Dim strUser As String
Dim strAddress As String
Dim strAccountName As String
Dim blnFound As Boolean
blnFound = False
Set oNS = Application.GetNamespace("MAPI")
Set colAccounts = oNS.Accounts
For Each oAccount In colAccounts
If oAccount.AccountType = OlAccountType.olPop3 Then
strAddress = oAccount.SmtpAddress
strUser = oAccount.UserName
strAccountName = oAccount.DisplayName
blnFound = True
Exit For
End If
Next
If blnFound Then
Set myMailItem = Application.CreateItem(olMailItem)
myMailItem.Subject = "Sent using: " & strAccountName
myMailItem.Body = "Sent by " & strUser & vbCrLf & "Sent using the " & strAddress & " SMTP address."
myMailItem.Recipients.Add ("test@test.com")
myMailItem.Recipients.ResolveAll
Set myMailItem.SendUsingAccount = oAccount
myMailItem.Send
End If
End Sub
|