Send email by Using POP3 : Email « Outlook « VBA / Excel / Access / Word

Send email by Using POP3

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

    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 ("")
        Set myMailItem.SendUsingAccount = oAccount
    End If
End Sub


Related examples in the same category

1.Send email for all records in an Access table
2.Display the information in a list of mails
3.Searching for Items
4.Adds an addressee, a subject, and body text; applies the HTML format; sets the importance to high; and sends the message:
5.Sending a Message
6.Send a table through email
7.Using the CreateItem Method to Create Default Items
8.Send out an email by using the DoCmd.SendObject