How do I nominate sender email in following code

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
LVL 1
Rob4077Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rob4077Author Commented:
Thanks for your answer. Exactly what I wanted.
0
Rob4077Author 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?
0
Rgonzo1971Commented:
Not that I know about
0
Rob4077Author Commented:
Ok that's fine. I've just created a noreply email address that has no space. Works the way I want. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.