Envoi d'emails HTML avec variables qui contiennent des diacritiques
Bonjour le Forum,
J'ai créé une application VBA qui envoit des emails automatiquement avec un compte gmail.
Dans le corps de l'email, en HTML, quand j'ai p.ex. un é, j'écris é
Cela marche très bien.
Mais dans mon corps d'email, j'utilise aussi des variables de type string, p.ex. une variable SpecialPrenoms qui peut contenir "Frédéric"
Quand j'ai un accent dans une variable, et qu'on va voir dans les emails reçus:
--> si le destinataire a une boîte gmail, pas de problème tous les accents y sont bien
--> si le destinataire a une boîte Outlook : les accents qui se trouvent dans les variables ne s'affichent pas. Ceux qui se trouvent hors des variables s'affichent bien.
Comment puis-je résoudre cela ?
Voici un extrait de mon code...
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| '(...)
dim body as variant
dim SpecialPrenoms as string
'(...)
for each c in Range("Q4:Q500")
SpecialPrenom = c.offset(0,9).value
body = "<p><strong>Assurance</strong><br />" & SpecialPrenoms & " : tu es extérieur au (...)</p>"
next C
'(...) |
Et ma macro d'envoi, récupérée du forum :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| Public Sub MailEnvoi(Serveur, Identify, User, PassWord, Port, Delay, Expediteur, Dest, DestEnCopy, BCC, Objet, Body, Pj, Optional factice As String)
' macro pour envoyer les mails
Dim msg
Dim Conf
Dim Config
Dim ess
Dim splitPj
Dim IsplitPj
Set msg = CreateObject("CDO.Message") 'pour la configuration du message
Set Conf = CreateObject("CDO.Configuration") 'pour la configuration de l'envoi
Dim strHTML
Set Config = Conf.Fields
' Configuration des parametres d'envoi
'(SMTP - Identification - SSL - Password - Nom Utilisateur - Adresse messagerie)
With Config
If Identify = True Then
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = User
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = PassWord
End If
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = Port
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Serveur
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = Delay
.Update
End With
'Configuration du message
'If E_mail.Sign.Value = Checked Then Convert ServeurFrm.SignTXT, ServeurFrm.Text1
With msg
Set .Configuration = Conf
.From = Expediteur
.To = Dest
.CC = DestEnCopy
.BCC = BCC
.Subject = Objet
.HTMLBody = Body
If Pj <> "" Then
splitPj = Split(Pj & ";", ";")
For IsplitPj = 0 To UBound(splitPj)
If Trim("" & splitPj(IsplitPj)) <> "" Then
.AddAttachment Trim("" & splitPj(IsplitPj))
End If
Next
End If
If Dest <> "" Then .Send 'envoi du message
End With
' reinitialisation des variables
Set msg = Nothing
Set Conf = Nothing
Set Config = Nothing
End Sub |
Merci d'avance pour votre aide !