[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

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
0
Rob4077
Asked:
Rob4077
  • 3
  • 2
1 Solution
 
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
 
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now