Note: The other languages of the website are Google-translated. Back to English
Accedi  \/ 
x
or
x
Registrati  \/ 
x

or

Come modificare automaticamente la firma in base ai destinatari in Outlook?

Per impostazione predefinita, Outlook ha una funzione incorporata che consente agli utenti di modificare automaticamente la firma durante l'invio di e-mail tramite diversi account di posta elettronica. Ma oltre a ciò, qui ti mostrerò il metodo per cambiare automaticamente la firma in base a diversi destinatari nel campo A in Outlook.

Cambia automaticamente la firma in base ai destinatari con il codice VBA


Cambia automaticamente la firma in base ai destinatari con il codice VBA

Seguire i passaggi seguenti per applicare firme diverse ai destinatari corrispondenti durante l'invio di e-mail in Outlook.

1. Innanzitutto, è necessario disabilitare la funzione di firma allegata automaticamente in Outlook. Fare clic su Compila il > Opzioni per aprire il Opzioni di Outlook finestra.

2. Nel Opzioni di Outlook finestra, selezionare posta nel riquadro di sinistra, quindi fare clic su firme nel pulsante Scrivi messaggi sezione. Vedi screenshot:

3. Nel Firme e articoli di cancelleria finestra di dialogo, vai al Scegli la firma predefinita sezione sotto il Firma e-mail scheda, seleziona un account di posta elettronica nel file Account email elenco a discesa, quindi scegliere (Nessuno) dal Nuovo messaggio e Risposte / inoltri elenchi a discesa. Ripeti questi passaggi finché tutti gli account di posta elettronica non sono impostati su (Nessuno). Quindi fare clic su OK pulsante.

Note:: Puoi anche creare le firme necessarie in questo file Firme e articoli di cancelleria la finestra di dialogo.

4. Fare clic sul OK quando ritorna il Opzioni di Outlook finestra.

5. premi il altro + F11 chiavi per aprire il Microsoft Visual Basic, Applications Edition finestra.

6. Nel Microsoft Visual Basic, Applications Edition finestra, fare doppio clic Questa sessione di Outlook nel riquadro di sinistra per aprire la finestra del codice e la copia sotto il codice VBA nella finestra. Vedi screenshot:

Codice VBA: modifica automaticamente la firma in base ai destinatari in Outlook

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'Updated by ExtendOffice 2020/6/12
Dim xMailItem As MailItem
Dim xRecipients As Recipients
Dim xRecipient As Recipient
Dim xRcpAddress As String
Dim xSignatureFile, xSignaturePath As String
Dim xFSO As Scripting.FileSystemObject
Dim xDoc As Document
On Error Resume Next
Set xFSO = New Scripting.FileSystemObject
If Item.Class <> olMail Then Exit Sub
Set xMailItem = Item
Set xRecipients = xMailItem.Recipients
xSignaturePath = CreateObject("WScript.Shell").SpecialFolders(5) + "\Microsoft\Signatures\"
For Each xRecipient In xRecipients
    If xRecipient.AddressEntry.AddressEntryUserType = olExchangeUserAddressEntry Then
        xRcpAddress = xRecipient.AddressEntry.GetExchangeUser.PrimarySmtpAddress
    Else
        xRcpAddress = xRecipient.AddressEntry.Address
    End If
    Select Case xRcpAddress
        Case "Email Address 1"
            xSignatureFile = xSignaturePath & "aaa.htm"
            Exit For
        Case "Email Address 2", "Email Address 3"
            xSignatureFile = xSignaturePath & "bbb.htm"
            Exit For
        Case "Email Address 4"
            xSignatureFile = xSignaturePath & "ccc.htm"
            Exit For
    End Select
Next
VBA.DoEvents
Set xDoc = xMailItem.GetInspector.WordEditor
xDoc.Application.Selection.EndKey
xDoc.Application.Selection.InsertParagraphAfter
xDoc.Application.Selection.MoveDown Unit:=wdLine, Count:=1
xDoc.Application.Selection.InsertFile FileName:=xSignatureFile, Link:=False, Attachment:=False
End Sub

Note:

  • 1). Nel codice VBA, sostituire il "Indirizzo e-mail 1/2/3/4"Con determinati indirizzi email dei destinatari.
  • 2). "aaa.htm""bbb.htm" e "ccc.htm"sono la firma specificata che invierai ai destinatari corrispondenti.
  • 3). In questo caso, la firma "aaa"Verrà inviato a"Indirizzo e-mail 1", firma "bbb"Verrà inviato a"Indirizzo e-mail 2" e "Indirizzo e-mail 3", e "Indirizzo e-mail 4"Riceverà l'email incorporata con la firma"ccc". Si prega di modificarli in base alle proprie esigenze.
  • 4). Se ci sono più destinatari in un'e-mail, il codice funziona solo per il primo. E tutti i destinatari riceveranno l'e-mail con la stessa firma specificata per quel destinatario.

7. Quindi fare clic Strumenti > Referenze per andare al Referenze-Progetto la finestra di dialogo. Nella finestra di dialogo, controlla entrambi i file Libreria di oggetti di Microsoft Word della scuola e il Runtime di script Microsoft opzioni, quindi fare clic su OK pulsante, vedi screenshot:

8. premi il altro + Q i tasti per chiudere il file Microsoft Visual Basic, Applications Edition finestra.

D'ora in poi, dopo aver composto un'e-mail e aver premuto il pulsante Invia, la firma corrispondente verrà automaticamente inserita alla fine del corpo dell'e-mail in base all'indirizzo e-mail del destinatario nel campo A.


Inserisci automaticamente la data corrente come firma durante l'invio di e-mail in Outlook:

Se desideri inserire il timestamp come firma nel corpo dell'e-mail durante la creazione / risposta / inoltro di nuove e-mail in Outlook, puoi abilitare il Aggiungi la firma della data quando crei una nuova email, rispondi e inoltra possibilità di Kutools per Outlook per ottenerlo. Vedi screenshot:
Scaricalo e provalo subito (percorso gratuito di 60 giorni)


Kutools for Outlook: porta 100 funzionalità avanzate in Outlook e semplifica notevolmente il lavoro!

  • Auto CC / BCC dalle regole durante l'invio di e-mail; Avanzamento automatico Email multiple personalizzate; Risposta automatica senza server di scambio e più funzioni automatiche ...
  • Avviso BCC - mostra il messaggio quando provi a rispondere a tutti se il tuo indirizzo e-mail è nell'elenco BCC; Ricorda quando mancano allegatie altre funzioni di promemoria ...
  • Rispondi (tutti) con tutti gli allegati nella conversazione di posta; Rispondi a molte email in secondi; Aggiunta automatica di saluto quando rispondi; Aggiungi la data all'oggetto ...
  • Strumenti per gli allegati: gestisci tutti gli allegati in tutti i messaggi, Scollegamento automatico, Comprimi tutto, Rinomina tutto, Salva tutto ... Rapporto rapido, Conta le email selezionate...
  • E-mail spazzatura potenti per abitudine; Rimuovi messaggi e contatti duplicati... Consentono di fare in modo più intelligente, veloce e migliore in Outlook.
girato kutools outlook scheda kutools 1180x121
girato kutools outlook kutools plus tab 1180x121
 
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Seth · 2 months ago
    This script is great and functional for what I was looking for. Is it possible to have the code differentiate if the message is new or a reply as well as the email domain? For example to further select a separate signature for replies to external recipients vs a new message to external recipients?

    Thank you for sharing.
  • To post as a guest, your comment is unpublished.
    jcamino · 5 months ago
    Great script. Thank you.Any way to insert the signature before hitting send to preview. I know I can delay send and look at it in outbox. Currently it doesn't appear until I hit send. If not is there any software that will automatically assign a signature based on Contact. We have been using a program for many years that worked great but it does not work in new versions of Outlook.
  • To post as a guest, your comment is unpublished.
    TimS · 8 months ago
    Hello Crystal,

    I am interested in the VBA code you wrote for "pauli" below, but when I run it, the following error is generated (and the "XDoc as Document" code line is highlighted):

    "Compile error: User-defined type not defined"

    How can I resolve this issue please?

    Thank you!
    • To post as a guest, your comment is unpublished.
      crystal · 8 months ago
      Hi Tim,
      Before applying the code, please go to the References dialog to check the Microsoft Word Object Library box (as the attached image shown).
  • To post as a guest, your comment is unpublished.
    Tim · 8 months ago
    Hello Crystal,

    I am interested in the VBA code you wrote for "pauli" below, but when I run it, the following error is generated (and the "XDoc as Document" code line is highlighted):

    "Compile error: User-defined type not defined"

    How can I resolve this issue please?

    Thank you, Tim
  • To post as a guest, your comment is unpublished.
    Greg · 11 months ago
    Tim I have same issue. Wherever the user clicks last is where the image is inserted. Does anyone have a way to force the image just above the signature?
  • To post as a guest, your comment is unpublished.
    Tim · 1 years ago
    I have some weird behaviour with VBA-generated Outlook emails. The signature is added to the mail as intended, but not positioned in the bottom of the email but rather in the middle (looks like at the first empty space). Any idea why and how to overcome it?
  • To post as a guest, your comment is unpublished.
    pauli · 1 years ago
    Hi, I would like to apply this to differentiate signatures when sending internal and external emails. Therefore instead of recognizing specific email addresses I'd need to just differentiate by the recipient email address containing my firm's name inside it or not. Could you let me know how the code would be for this specific case?


    (For example if i wanted to sign with signature "internal.htm" when the recipient email contains the string "microsoft" and signature "external.htm" if it doesn't contain the string "microsoft". In this case addresses like 'jane@microsoft.com', 'tom@microsoft.support.com' and 'recruiting@microsoft.europe.com' would all be considered like the internal recipients for a Microsoft employee).

    Thanks!!
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi pauli,
      Please try the below code. Before applying the code, please go to the References dialog to check the Microsoft Word Object Library box (as the attached image shown).

      Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
      'Updated by ExtendOffice 2020/6/12
      Dim xMailItem As MailItem
      Dim xRecipients As Recipients
      Dim xRecipient As Recipient
      Dim xRcpAddress As String
      Dim xSignatureFile, xSignaturePath As String
      Dim xFSO As Scripting.FileSystemObject
      Dim xDoc As Document
      On Error Resume Next
      Set xFSO = New Scripting.FileSystemObject
      If Item.Class <> olMail Then Exit Sub
      Set xMailItem = Item
      Set xRecipients = xMailItem.Recipients
      xSignaturePath = CreateObject("WScript.Shell").SpecialFolders(5) + "\Microsoft\Signatures\"
      For Each xRecipient In xRecipients
      If xRecipient.AddressEntry.AddressEntryUserType = olExchangeUserAddressEntry Then
      xRcpAddress = xRecipient.AddressEntry.GetExchangeUser.PrimarySmtpAddress
      Else
      xRcpAddress = xRecipient.AddressEntry.Address
      End If
      If VBA.InStr(VBA.LCase(xRcpAddress), "@microsoft") > 0 Then 'Enter the string in the double quotation marks. If the recipient email address contains this string, the below signature "internal.htm" will be assigned to the email. Otherwise, assign the signature "external.htm".
      xSignatureFile = xSignaturePath & "internal.htm"
      Exit For
      Else
      xSignatureFile = xSignaturePath & "external.htm"
      End If
      Next
      VBA.DoEvents
      Set xDoc = xMailItem.GetInspector.WordEditor
      xDoc.Application.Selection.EndKey
      xDoc.Application.Selection.InsertParagraphAfter
      xDoc.Application.Selection.MoveDown Unit:=wdLine, Count:=1
      xDoc.Application.Selection.InsertFile FileName:=xSignatureFile, Link:=False, Attachment:=False
      End Sub
      • To post as a guest, your comment is unpublished.
        Daniela · 7 months ago
        Hi, Crystal,
        I have a question. When I am sending emails to both external and internal recipients how can I make it differentiate by choosing always external signature? Thanks
        • To post as a guest, your comment is unpublished.
          Random_Guest · 2 months ago
          You might have found the solution for yourself by now or abandoned this thread long time ago, but I feel the urge to finish this now. The simple answer to this question:

          Edit the If-Else-Clause (that differentiates between the two signatures) to the following:

          If VBA.InStr(VBA.LCase(xRcpAddress), "@microsoft") = 0 Then 'Enter the string in the double quotation marks. If the recipient email address contains this string, the below signature "internal.htm" will be assigned to the email. Otherwise, assign the signature "external.htm".
          xSignatureFile = xSignaturePath & "external.htm"
          Exit For
          Else
          xSignatureFile = xSignaturePath & "internal.htm"
          End If

          What happens now:

          If the recipient address from a list of recipient addresses does NOT contain the given string, use the external signature and stop looking at further recipients. Otherwise use the internal signature and look for the next recipient address.
  • To post as a guest, your comment is unpublished.
    calo.andrea.sportradar@gmail.com · 1 years ago
    Hi Crystal,

    what did you change to fix the images issue? I am using your latest code and I have the same problem as Amanda.
    Thanks
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Besides the code, the operation of step 7 has also changed. Please follow the instruction step by step to get it down.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi,
      Sorry for the mistake. The VBA has been updated again, and the images issue is totally fixed now.
  • To post as a guest, your comment is unpublished.
    Vysakh · 1 years ago
    Very nice script but the image files in my signature are not delivered right. Can you fix this issue ?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Vysakh,
      The code has been updated, and the images issue is fixed now. Sorry for the inconvenience.
  • To post as a guest, your comment is unpublished.
    Amanda · 1 years ago
    I added this clever script to Outlook 2013 and it correctly identifies and selects the different email signatures I use.

    I have a problem with one of the graphics that is part of one signature. Instead of the graphic being shown the "Sent Items" folder (and recipient) shows the email with the attached screen shot and trying to download the image does not work.

    If I disable the script and sign manually then the outgoing email is correct and the recipient gets what I intend. Even more interesting is that with another simpler signature where the graphic is just a straight line this is included albeit that the graphic is changed slightly.

    The graphic is a PNG file 80KB 5904 x 1024 pixels with a bit depth of 32 and I have tried smaller sizes down to 10KB 369 x 64 pixels which has not helped. My Outlook version is 15.0.5189.1000 32Bit Professional Plus 2013 on a Windows 10 Pro platform.

    I wonder if you can suggest a solution for this please.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear Amanda,
      We have updated the code. Thank you for reminding me the error.
  • To post as a guest, your comment is unpublished.
    gregoryt · 2 years ago
    Hello! Very nice script, but there is a problem when sending to excahnge addresses, the xRcpAddress returns the X400 name not the smtp address, this makes it impossible to select based on domain. Is there a workaround this?


    Just to improve I have changed the case statement to if using the inStr function to discern mails in bulk

    If InStr(xRcpAddress, "@example") Then
    xSignatureFile = xSignaturePath & "aaa.htm"
    End If
  • To post as a guest, your comment is unpublished.
    Devansh · 2 years ago
    How would this behave if there are multiple recipients?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Devansh,
      If there are multiple recipients in an email, the code only works for the first one. And all recipients will receive the email with the same signature specified to that person.
      If you want to incude different signatures when there are multiple recipients, the email should be sent separately to different recipients. And that will need another code to achieve.