Results 1 to 3 of 3
  1. #1
    Kentuky is offline Novice
    Windows 10 Access 2007
    Join Date
    Jun 2018
    Posts
    2

    How to send email in series from an specific account in outlook?

    Hello

    I have this code to send an email to birthday parties through outlook, where I have two email accounts, how can I specify which one is sending?



    The birthdays are obtained from a database in access 2007 through the query "Aniversariantes", which is composed of the fields: "name", "email" and "send".

    I apologize for my English.

    Thank you so mutch


    Public Subsendserialemail()

    Dim db As DAO.Database
    Dim rs As DAO.Recordset

    Dimemailto As String
    Dim emailsubject As String
    Dim emailtext As String

    Dim outapp Asoutlook.Application
    Dim outmail Asoutlook.MailItem
    Dim outstarted As Boolean

    On Error Resume Next
    Set outapp = GetObject(,"outlook.application")
    On Error GoTo 0
    If outapp Is Nothing Then
    Set outapp = CreateObject("outlook.application")
    outstarted = True
    End If

    Set db = CurrentDb
    Set rs =db.OpenRecordset("SELECT nome, email, enviar " & "FROMAniversariantes")

    Do Until rs.EOF

    emailto= rs.Fields("nome").Value & " <" &rs.Fields("email").Value & ">"

    emailsubject= "Feliz Aniversário"

    emailtext= Trim("Olá " & rs.Fields("nome").Value) &"!" & vbCrLf

    Ifrs.Fields("enviar").Value Then
    emailtext = emailtext & "Muitos parabéns!" & vbCrLf
    End If

    emailtext = emailtext & "A Direção do Clube"

    Setoutmail = outapp.CreateItem(olMailItem)
    outmail.To = emailto
    outmail.Subject = emailsubject
    outmail.Body = emailtext
    outmail.Send

    rs.MoveNext
    Loop

    rs.Close
    Set rs = Nothing
    Set db = Nothing

    If outstarted Then
    outapp.Quit
    End If

    Set outmail = Nothing
    Set outapp = Nothing

    End Sub

  2. #2
    Kudos is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Location
    Toronto, ON
    Posts
    29
    Not much experience with this, but try adding in:

    outmail.SentOnBehalfOfName = "your@email.com"

    ...right after:

    Set outmail = outapp.CreateItem(olMailItem)

    OR it might be outmail.SendUsingAccount which is a little tricker to grab, here's a link:

    https://www.slipstick.com/developer/...cific-account/

  3. #3
    Kentuky is offline Novice
    Windows 10 Access 2007
    Join Date
    Jun 2018
    Posts
    2
    Hello Kudos,

    tested and approved.

    Thank you very much.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Send email using VBA and outlook
    By hinchi1 in forum Access
    Replies: 8
    Last Post: 10-17-2017, 12:11 PM
  2. Replies: 5
    Last Post: 09-14-2015, 07:24 AM
  3. Replies: 5
    Last Post: 07-21-2015, 05:27 AM
  4. How to send formatted email without outlook
    By alex1888 in forum Programming
    Replies: 2
    Last Post: 06-04-2015, 08:32 PM
  5. Send email in Outlook with attachment
    By kelkan in forum Programming
    Replies: 1
    Last Post: 02-01-2013, 10:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums