none
Including sender information in an email RRS feed

  • Question

  • I want to generate an email from my Access 2010 program, but I can't find the sender's name, address, title etc. to include after the body of the email.  I can generate an email like below with no name and address:

    Public Sub sendmeTest()
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim obj As Outlook.MailItem

    Set objOutlook = GetObject(, "Outlook.Application")
       
       Set objOutlook = CreateObject("Outlook.Application")
       Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
        With objOutlookMsg
         Set objOutlookRecip = .Recipients.Add("John.Smith@td.com")
           
              objOutlookRecip.Type = olTo
          .Subject = "Monthly Reports"
          .Body = "Attached are this month's monthly reports.  Let me know if you have any questions."
          .CC = "Allison.Jones@td.com"
          .Importance = olImportanceNormal
         
             
         ' .Send
            .Display
        End With
       Set objOutlookMsg = Nothing
       Set objOutlook = Nothing
       Set objOutlookRecip = Nothing
    Exit Sub
    End Sub

    The bottom of the email is blank. I am hoping to be able to include at least the name and address of the sender. Any ideas?


    Dean J. Waring

    Thursday, March 2, 2017 8:44 PM

Answers

  • Hi DeanJW2006,

    you need to create object of Outlook application.

    currently that uses object of MS Access Application so it is giving you an error.

    use code below.

    Sub DisplayCurrentUser()
     
     Dim myNamespace As outlook.NameSpace
     Dim ol As outlook.Application
     
     Set ol = GetObject(, "Outlook.Application")
     Set myNamespace = ol.GetNamespace("MAPI")
     
     MsgBox myNamespace.CurrentUser
     
    End Sub

    Output:

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by DeanJW2006 Friday, March 3, 2017 1:06 PM
    Friday, March 3, 2017 2:29 AM
    Moderator

All replies

  • Hello Dean,

    The CurrentUser property of the Namespace class returns the display name of the currently logged-on user as a Recipient object.

    Sub DisplayCurrentUser()  
     Dim myNamespace As Outlook.NameSpace 
     Set myNameSpace = Application.GetNameSpace("MAPI")  
     MsgBox myNameSpace.CurrentUser  
    End Sub

    You can use the Name and Address properties of the Recipient class to include in the email.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Thursday, March 2, 2017 9:00 PM
  • Not sure why I get an error when just running the sub by itself:


    Dean J. Waring

    Thursday, March 2, 2017 9:49 PM
  • Hi DeanJW2006,

    you need to create object of Outlook application.

    currently that uses object of MS Access Application so it is giving you an error.

    use code below.

    Sub DisplayCurrentUser()
     
     Dim myNamespace As outlook.NameSpace
     Dim ol As outlook.Application
     
     Set ol = GetObject(, "Outlook.Application")
     Set myNamespace = ol.GetNamespace("MAPI")
     
     MsgBox myNamespace.CurrentUser
     
    End Sub

    Output:

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by DeanJW2006 Friday, March 3, 2017 1:06 PM
    Friday, March 3, 2017 2:29 AM
    Moderator
  • Thank you....

    Dean J. Waring

    Friday, March 3, 2017 1:06 PM
  • check out http://www.rondebruin.nl/win/s1/outlook/signature.htm

    very good article...and again thank you for your help.


    Dean J. Waring

    Friday, March 3, 2017 8:20 PM