Add the Senders email address to the Body of an Email

ddrew

seasoned user
Local time
Today, 17:56
Joined
Jan 26, 2003
Messages
911
I want to automate an email to include the senders email addres with some text in the body of the email. Can somebody tell me how to it, thanks.

Code:
Private Sub send_mail_Click()
 Dim olApp As Object
   Dim objMail As Object

   On Error Resume Next 'Keep going if there is an error
   Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open

    If Err Then 'Outlook is not open
       Set olApp = CreateObject("Outlook.Application") 'Create a new instance
    End If
  'Create e-mail item
   Set objMail = olApp.CreateItem(olMailItem)

   With objMail
   'Set body format to HTML
     .BodyFormat = olFormatHTML
     .To = "da.drew@hotmail.co.uk"
     '.Cc = "ccaddress@yourmailaddress.com"
     .Subject = "Gundog Manager Registration"
     
     .HTMLBody = "<htmltags>This email confirms that a new user has registered a copy of Gundog Manager</htmltags>"
     .Send
   End With

  MsgBox "Operation completed successfully"

End Sub
 
This should give you the email Address..
Code:
Dim fromStr As String
fromStr = olApp.Application.Session.Accounts.Item(1).SmtpAddress
 
This should give you the email Address..
Code:
Dim fromStr As String
fromStr = olApp.Application.Session.Accounts.Item(1).SmtpAddress

Thanks, but where do I need to insert it to get it into the boby of the email? I currently have:
Code:
.HTMLBody = "<htmltags>This email confirms that a new user [COLOR="Red"](email address to appear here) [COLOR="Black"] [/COLOR][/COLOR]has registered a copy of Gundog Manager</htmltags>"
 
How about?
Code:
.HTMLBody = "<HTMLtags>This email confirms that a new user " & _
            olApp.Application.Session.Accounts.Item(1).SmtpAddress & _
            " has registered a copy of Gundog Manager.</HTMLtags>"
 

Users who are viewing this thread

Back
Top Bottom