How do I nominate sender email in following code

Rob4077
Rob4077 used Ask the Experts™
on
I am using the following partial code to reply to some emails I receive. What I want to do is have the sender set to "noreply@mydomain.com". Is that possible?

    Dim olkMsg As Outlook.MailItem
    Dim olkRpl As Outlook.MailItem
   
    Set olkMsg = Application.ActiveExplorer.Selection(1)
    Set olkRpl = olkMsg.Reply
   
    With olkRpl
        Select Case olkRpl.BodyFormat
            Case olFormatHTML
                olkRpl.HTMLBody = REPLY_HTML & olkRpl.HTMLBody
            Case Else
                olkRpl.Body = REPLY_TEXT & olkRpl.Body
        End Select
        olkRpl.Attachments.Add sAttach
       
        olkRpl.Send
'        olkMsg.Move Session.GetDefaultFolder(olFolderInbox).Folders("Deleted Items")
        olkMsg.Delete
    End With
       
    Set olkMsg = Nothing
    Set olkRpl = Nothing
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Hi,

pls try

Sub SendUsingAccount()
 
    Dim olkAccount As Outlook.account
    Dim myAccount As Outlook.account
    Dim olkMsg As Outlook.MailItem
    Dim olkRpl As Outlook.MailItem
    
    Set olkMsg = Outlook.ActiveExplorer.Selection(1)
    Set olkRpl = olkMsg.Reply
    
    For Each olkAccount In Application.Session.Accounts
        If oAccount.DisplayName = "noreply@mydomain.com" Then
        Set myAccount = olkAccount
        Exit For
    Next
    If myAccount Is Nothing Then Exit Sub
    
    With olkRpl
        Select Case olkRpl.BodyFormat
            Case olFormatHTML
                olkRpl.HTMLBody = REPLY_HTML & olkRpl.HTMLBody
            Case Else
                olkRpl.Body = REPLY_TEXT & olkRpl.Body
        End Select
        olkRpl.Attachments.Add sAttach
        
        'olkRpl.Send
        olkRpl.SendUsingAccount = oAccount
'        olkMsg.Move Session.GetDefaultFolder(olFolderInbox).Folders("Deleted Items")
        olkMsg.Delete
    End With
        
    Set olkMsg = Nothing
    Set olkRpl = Nothing

End Sub

Open in new window

EDIT

or you could just use

 .SentOnBehalfOfName = """No Reply"" <noreply@mydomain.com>"

Regards

Author

Commented:
Thanks for your answer. Exactly what I wanted.

Author

Commented:
Just tried the second option and realised that it still has me as the sender and if I reply to the reply it will come to me. Is there a way of having it look like its been sent from the NoReply address and if they do a Reply that reply gets addressed to the NoReply address WITHOUT me having to have created a NoReply address?
Top Expert 2016

Commented:
Not that I know about

Author

Commented:
Ok that's fine. I've just created a noreply email address that has no space. Works the way I want. Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial