none
VBA Set Sender Address ( or SendAs ) for NDR Resend RRS feed

  • Question

  • Hi All

    For my Macro i need to Resend message from NDR ( Qurantine Mailbox )

    I can open NDR & Execute Resend but i need to specify Sender Address ( ResendFrom) - how to do this? Message Class is IPM.Resend and there is no Sender Address or SentOnBehalfOfName.


    Best Wishes, Andrew Golubenkoff

    Tuesday, January 12, 2016 8:09 AM

All replies

  • Hello Andrew, 

    The SendUsingAccount property of the MailItem class allows to set an Account object that represents the account under which the MailItem is to be sent.

    Sub SendUsingAccount() 
     
     Dim oAccount As Outlook.account 
     
     For Each oAccount In Application.Session.Accounts 
     
     If oAccount.AccountType = olPop3 Then 
     
     Dim oMail As Outlook.MailItem 
     
     Set oMail = Application.CreateItem(olMailItem) 
     
     oMail.Subject = "Sent using POP3 Account" 
     
     oMail.Recipients.Add ("someone@example.com") 
     
     oMail.Recipients.ResolveAll 
     
     oMail.SendUsingAccount = oAccount 
     
     oMail.Send 
     
     End If 
     
     Next 
     
    End Sub 

    Tuesday, January 12, 2016 8:41 AM
  • Hi,

    Yes i know this, but it is not a MailItem :(


    Best Wishes, Andrew Golubenkoff


    Tuesday, January 12, 2016 9:12 AM
  • Hi Andrew,

    >> it is not a MailItem

    If this is not a mailItem, what is it? I made a test with outlook built-in resend function, but the outlook UI is different from your picture. Is the send again function your custom outlook add in form? How did you achieved your resend?
    Based on your original post, as the reply from Eugene, there is no resend method in outlook object model, and Eugene shared a workaround for your requirement. For details about sending email from a template, you could refer the link below:

    # Resend Emails with VBA
    https://social.msdn.microsoft.com/Forums/office/en-US/c23546c2-23a7-439f-89aa-6766732e8ff9/resend-emails-with-vba?forum=outlookdev

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, January 13, 2016 3:35 AM
  • Hi,

    This is Message Class IPM.Resend-

    1. We have Quarantine Mailbox ( Exchange Content Filter ) - for example spam@domain

    2. We receive NDR Message ( Class=Report.IPM.Note.NDR )

    3. This message contain our original message as hidden attach

    4. To SendAgain manually - i press  send again button in Outlook and Than set ResendFrom to spam@domain - and message Resending to Recipient with all original Fields including sender address ( no spam@domain sender - only original )

    I need Outlook Macro to do this with 1 button.

    I tried to get attached original Message, SaveAs file, Create New MailItem from Template & than resendAs actiion - message sent but returned with Error that i doesn't have Rights to send As. :(

    Now i find the way to invoke outlook SendAgain Button, but can't send :( Please help :)

    My Code:

    Sub NDR1()
        Dim objSelection As Outlook.Selection
        Dim obj As ReportItem
        Dim objInsp As Outlook.Inspector
        
        Set objSelection = Application.ActiveExplorer.Selection
        Set obj = objSelection.item(1)
        
        obj.Display
            
        Set objInsp = ActiveInspector
        objInsp.CommandBars.ExecuteMso ("SendAgain")
         
        Set myItem = Application.ActiveInspector.CurrentItem
        
    ' show MessageClass
        MsgBox (obj.MessageClass & " ---- " & myItem.MessageClass)
        
    
    ' Here i need to Set Sender Address and Sent Message
    
    ' Close windows    
    
        myItem.Close (olDiscard)
        obj.Close (olDiscard)
        
        
    End Sub


    Best Wishes, Andrew Golubenkoff

    Wednesday, January 13, 2016 7:11 AM
  • Hi Andrew,

    Could you make clearly the questions below?
    1. What is the Send again form? Is it your custom form?
    2. How did you defined “ExecuteMso ("SendAgain")”? Is SendAgain your custom mso button?

    I did not have the Send again form like yours.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, January 14, 2016 9:23 AM
  • Hi,


    Send Again it Standart for Outlook , there is no Custom Forms

    ExecutMSO - Is standart to Outlook 2013 to.


    This all for NDR (Non Delivery Message Report ) from Exchange Server for Exchange Recipient

    In my situation for Quarantine Mailbox:

    https://technet.microsoft.com/en-us/library/bb123746%28v=exchg.150%29.aspx

    Best Wishes, Andrew Golubenkoff


    Friday, January 15, 2016 11:55 AM
  • Hi Andrew,

    I suggest you start your outlook in safe model to check whether you could see the Send Again.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, January 19, 2016 7:56 AM
  • I CAN invoke SendAgain using this method but i can't Set ResendFrom  - how to do this ?

    If you need example of message - i can attach one here


    Best Wishes, Andrew Golubenkoff

    Wednesday, January 20, 2016 1:49 PM
  • Hi Andrew,

    test this code

    Sub NDR1()
        Dim objSelection As Outlook.Selection
        Dim obj As ReportItem
        Dim objInsp As Outlook.Inspector
        
        Dim MyAtt
        Dim oNamespace
        Dim myItem
        Dim i
    
        Set objSelection = Application.ActiveExplorer.Selection
        Set obj = objSelection.item(1)
    
        obj.Display
    
        Set objInsp = ActiveInspector
        Set MyAtt = obj.Attachments.item(1)
        MyAtt.SaveAsFile Environ("TEMP") & "\" & _
                         MyAtt.fileName
    
    
    
        'objInsp.CommandBars.ExecuteMso ("SendAgain")
        Set oNamespace = Application.GetNamespace("MAPI")
        Set myItem = oNamespace.OpenSharedItem(Environ("TEMP") & "\" & MyAtt.fileName)
        myItem.Display
    
        For i = myItem.Recipients.count To 1 Step -1
            myItem.Recipients.item(i).Delete
        Next i
        myItem.Recipients.add "TOTO@titi.fr"
        myItem.Send
    
        ' Here i need to Set Sender Address and Sent Message
    
        ' Close windows
    
    
        obj.Close (olDiscard)
    
    
    End Sub


    Have a nice day. Oliv-


    • Edited by Oliv- Friday, January 22, 2016 10:55 AM
    Thursday, January 21, 2016 1:58 PM
  • Hi Oliv-

    Code is ok, but i need to set ResendFrom or SentOnBehalfOfName - but i cannot - how to set this parameter?

    ( I need to preserve all original sender & recipient addresses ) and send on Behalf of Nameof other mailbox.


    Best Wishes, Andrew Golubenkoff

    Friday, January 22, 2016 7:57 AM
  • Hi,

    Replace myItem.Display with 

    myItem.SentOnBehalfOfName = "SENDER"

    myItem.Display

     

    It's right it's a workaround, but i'm going to test another solution


    Have a nice day. Oliv-


    • Edited by Oliv- Friday, January 22, 2016 8:37 AM
    Friday, January 22, 2016 8:36 AM
  • Yes i know this option, but it doesn't work - message returned with ndr that i can't send as this sender :(

                This message could not be sent. Try sending the message again later, or contact your network administrator. You do not have the permission to send the message on behalf of the specified user. Error is [0x80070005-0x0004dc-0x000524].
    
    


    Best Wishes, Andrew Golubenkoff

    Friday, January 22, 2016 9:09 AM
  • P.S I tried to perform SendUsingAccount - but no success - error the same :(

    Best Wishes, Andrew Golubenkoff

    Friday, January 22, 2016 9:10 AM
  • Do you have permissions on this user ? Do you want to use a other server account ?

    Have a nice day. Oliv-

    Friday, January 22, 2016 10:50 AM
  • Andrew,

    this is a new code wich preserve original recipients.

     you need REDEMPTION

    http://www.dimastr.com/redemption/Redemption.zip

    Sub resend()
    '---------------------------------------------------------------------------------------
    ' Procedure : resend
    ' Author    : Oliv
    ' Date      : 22/01/2016
    ' Purpose   : RESEND olreport with new recipient and SentOnBehalfOfName
    '---------------------------------------------------------------------------------------
    '
    
        Dim oItem
        Dim objInsp As Outlook.Inspector
        Set oItem = ActiveInspector.CurrentItem
        Set objInsp = oItem.GetInspector
        objInsp.CommandBars.ExecuteMso ("SendAgain")
    
        Set oItem = ActiveInspector.CurrentItem
    
        Dim RDOSession, Mail, recip
        Set RDOSession = CreateObject("Redemption.RDOSession")
        RDOSession.MAPIOBJECT = Application.Session.MAPIOBJECT
        oItem.Save
        Set Mail = RDOSession.GetMessageFromID(oItem.EntryID)
        For Each recip In Mail.Recipients
            Debug.Print recip.Name
        Next
        Dim SmtpMAILtoReplace
        SmtpMAILtoReplace = Mail.Recipients(Mail.Recipients.count).SmtpAddress
        Dim i
        For i = Mail.Recipients.count To 1 Step -1
            If Mail.Recipients(i).SmtpAddress = SmtpMAILtoReplace Then Mail.Recipients(i).Delete
        Next
    
        Set recip = Mail.Recipients.add("TOTO@titi.fr")
        recip.Type = olTo
        recip.Resolve
        Dim AddressEntry
        Set AddressEntry = RDOSession.AddressBook.GAL.ResolveName("SENDER")
        Set Mail.SentOnBehalfOf = AddressEntry
    
        Mail.Save
        Mail.Send
        oItem.Close olSave
    End Sub


    Have a nice day. Oliv-


    Friday, January 22, 2016 10:54 AM
  • Hi ! It's Brilliant!!!! It's Working! Thank you a lot!

    ( is it possible to do this without Redemption?  :) )

    Here the Complete Code for everyone:

    Sub  ResendAs_ALL()
    	'---------------------------------------------------------------------------------------
    	' Procedure : resend
    	' Author    : Oliv  (https://social.msdn.microsoft.com/profile/oliv- )
    	' Date      : 22/01/2016
    	' Purpose   : RESEND olreport with new recipient and SentOnBehalfOfName
    	'
    	' you need REDEMPTION
    	' http://www.dimastr.com/redemption/Redemption.zip
    	'---------------------------------------------------------------------------------------
    	'
    	
    	' Show item
    	Dim objSelection As Outlook.Selection
    	Dim obj As ReportItem
    	
    	Set objSelection = Application.ActiveExplorer.Selection
    	
    	For Each obj In objSelection
    		'Set obj = objSelection.item(1)
    		
    		' Display Item
    		obj.Display
    		
    		Dim oItem
    		Dim objInsp As Outlook.Inspector
    		Set oItem = ActiveInspector.CurrentItem
    		Set objInsp = oItem.GetInspector
    		objInsp.CommandBars.ExecuteMso("SendAgain")
    		
    		Set oItem = ActiveInspector.CurrentItem
    		
    		Dim RDOSession, Mail, recip
    		Set RDOSession = CreateObject("Redemption.RDOSession")
    		RDOSession.MAPIOBJECT = Application.session.MAPIOBJECT
    		oItem.save
    		Set Mail = RDOSession.GetMessageFromID(oItem.EntryID)
    		For Each recip In Mail.Recipients
    			Debug.Print recip.Name
    		Next
    		
    		Dim AddressEntry
    		Set AddressEntry = RDOSession.AddressBook.GAL.ResolveName("SENDER") ' here Name of User to Send On Behalf Of
    		Set Mail.SentOnBehalfOf = AddressEntry
    		
    		' Save and Send Message
    		Mail.save
    		Mail.Send
    		
    		' Close  & Delete NDR
    		
    		oItem.Close olSave
    		
    		obj.Close olDiscard
    		obj.Delete
    	Next
    	
    End Sub


    Best Wishes, Andrew Golubenkoff




    Friday, January 22, 2016 12:09 PM
  • Hi Oliv

    I found some issue with this code -  users receiving messages without attachments and message looks like resend from - not like original Mail. :(

    So code is not functional - how we can fix this?


    Best Wishes, Andrew Golubenkoff

    Monday, February 8, 2016 2:29 PM