IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Pièce jointe illisible lors de l'envoi d'un e-mail


Sujet :

C#

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17
    Points : 11
    Points
    11
    Par défaut Pièce jointe illisible lors de l'envoi d'un e-mail
    Bonjour,
    Je rencontre un problème lorsque j'envoie une pièce jointe dans un e-mail à partir d'un code C#. L'e-mail s'envoie correctement mais lorsque je le consulte (dans Outlook ou tout autre client mail) la pièce jointe a changé de nom (commence par "=_UTF-8_B_" et porte l'extension ".dat") et est illisible.

    Voici le code que j'utilise pour envoyer mon e-mail:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    try
    {
        using (MailMessage email = new MailMessage())
        {
            // Création du mail
            MailAddress expediteur = new MailAddress("noreply@hotmail.com", "Seb");
            MailAddress destinataire = new MailAddress("noreply@hotmail.com");
     
            email.Sender = expediteur;
            email.From = expediteur;
            email.To.Add(destinataire);
            email.Subject = "Test pièce jointe";
            email.Body = "Hello world.";
            email.IsBodyHtml = false;
     
            // Ouverture et ajout de la pièce jointe
            email.Attachments.Add(new Attachment(@"D:\Temp\Défense orale du rapport de stage SJA 2011.docx"));
     
            // Envoi
            SmtpClient smtp = new SmtpClient();
            smtp.Send(email);
        }
     
        lInfo.Text = "E-mail envoyé!";
    }
    catch (Exception ex)
    {
        lInfo.Text = string.Format("Erreur: {0}", ex.Message);
    }
    Le code est exécuté dans une application ASP.NET. Le serveur SMTP est donc enregistré dans le web.config.

    En clair, si j'utilise la ligne suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    email.Attachments.Add(new Attachment(@"D:\Temp\Défense orale du rapport de stage SJA 2011.docx"));
    A la réception du mail, le nom de la pièce jointe est devenu: =_utf-8_B_RMOpZmVuc2Ugb3JhbGUgZHUgcmFwcG9y.dat.
    De plus, j'ai remarqué que le contenu du fichier a été codé en base 64 (dans la source du mail). Ce qui le rend totalement illisible.

    Si, par contre, je renomme le fichier avec un nom plus court :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    email.Attachments.Add(new Attachment(@"D:\Temp\test.docx"));
    La pièce jointe est tout-à-fait lisible.

    Pouvez-vous me dire pourquoi la pièce jointe de l'e-mail devient illisible quand celle-ci porte un nom un peu grand?
    Ai-je commis une erreur dans le code d'envoi de l'e-mail?


    Merci d'avance pour vos réponses.

    PS: je ne pense pas que le problème provienne de notre serveur SMTP car, si j'envoie ma pièce jointe via Outlook, tout se passe correctement.

    Config:
    Windows 7
    Framework 4
    Visual Studio 2010

  2. #2
    Membre régulier Avatar de bobjoumi
    Profil pro
    Inscrit en
    Février 2009
    Messages
    94
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Février 2009
    Messages : 94
    Points : 86
    Points
    86
    Par défaut
    Bonjour, c'est surement pas ça que tu veux faire mais voila un classe qui pourrait être intéressante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
     
    using System;
    using System.Runtime.InteropServices;
    using System.IO;
    using System.Collections.Generic;
    using System.Windows.Forms;
     
     
    namespace Pgm
    {
        class MAIL
        {
     
            public bool AddRecipientTo(string email)
            {
                return AddRecipient(email, HowTo.MAPI_TO);
            }
     
            public bool AddRecipientCC(string email)
            {
                return AddRecipient(email, HowTo.MAPI_TO);
            }
     
            public bool AddRecipientBCC(string email)
            {
                return AddRecipient(email, HowTo.MAPI_TO);
            }
     
            public void AddAttachment(string strAttachmentFileName)
            {
                m_attachments.Add(strAttachmentFileName);
            }
     
            public int SendMailPopup(string strSubject, string strBody)
            {
                return SendMail(strSubject, strBody, MAPI_LOGON_UI | MAPI_DIALOG);
            }
     
            public int SendMailDirect(string strSubject, string strBody)
            {
                return SendMail(strSubject, strBody, MAPI_LOGON_UI);
            }
     
     
            [DllImport("MAPI32.DLL")]
            static extern int MAPISendMail(IntPtr sess, IntPtr hwnd,
                MapiMessage message, int flg, int rsv);
     
            int SendMail(string strSubject, string strBody, int how)
            {
                MapiMessage msg = new MapiMessage();
                msg.subject = strSubject;
                msg.noteText = strBody;
     
                msg.recips = GetRecipients(out msg.recipCount);
                msg.files = GetAttachments(out msg.fileCount);
     
                m_lastError = MAPISendMail(new IntPtr(0), new IntPtr(0), msg, how,
                    0);
                if (m_lastError > 1)
                    MessageBox.Show("MAPISendMail failed! " + GetLastError(),
                        "MAPISendMail");
     
                Cleanup(ref msg);
                return m_lastError;
            }
     
            bool AddRecipient(string email, HowTo howTo)
            {
                MapiRecipDesc recipient = new MapiRecipDesc();
     
                recipient.recipClass = (int)howTo;
                recipient.name = email;
                m_recipients.Add(recipient);
     
                return true;
            }
     
            IntPtr GetRecipients(out int recipCount)
            {
                recipCount = 0;
                if (m_recipients.Count == 0)
                    return IntPtr.Zero;
     
                int size = Marshal.SizeOf(typeof(MapiRecipDesc));
                IntPtr intPtr = Marshal.AllocHGlobal(m_recipients.Count * size);
     
                int ptr = (int)intPtr;
                foreach (MapiRecipDesc mapiDesc in m_recipients)
                {
                    Marshal.StructureToPtr(mapiDesc, (IntPtr)ptr, false);
                    ptr += size;
                }
     
                recipCount = m_recipients.Count;
                return intPtr;
            }
     
            IntPtr GetAttachments(out int fileCount)
            {
                fileCount = 0;
                if (m_attachments == null)
                    return IntPtr.Zero;
     
                if ((m_attachments.Count <= 0) | (m_attachments.Count >
                    maxAttachments))
                    return IntPtr.Zero;
     
                int size = Marshal.SizeOf(typeof(MapiFileDesc));
                IntPtr intPtr = Marshal.AllocHGlobal(m_attachments.Count * size);
     
                MapiFileDesc mapiFileDesc = new MapiFileDesc();
                mapiFileDesc.position = -1;
                int ptr = (int)intPtr;
     
                foreach (string strAttachment in m_attachments)
                {
                    mapiFileDesc.name = Path.GetFileName(strAttachment);
                    mapiFileDesc.path = strAttachment;
                    Marshal.StructureToPtr(mapiFileDesc, (IntPtr)ptr, false);
                    ptr += size;
                }
     
                fileCount = m_attachments.Count;
                return intPtr;
            }
     
            void Cleanup(ref MapiMessage msg)
            {
                int size = Marshal.SizeOf(typeof(MapiRecipDesc));
                int ptr = 0;
     
                if (msg.recips != IntPtr.Zero)
                {
                    ptr = (int)msg.recips;
                    for (int i = 0; i < msg.recipCount; i++)
                    {
                        Marshal.DestroyStructure((IntPtr)ptr,
                            typeof(MapiRecipDesc));
                        ptr += size;
                    }
                    Marshal.FreeHGlobal(msg.recips);
                }
     
                if (msg.files != IntPtr.Zero)
                {
                    size = Marshal.SizeOf(typeof(MapiFileDesc));
     
                    ptr = (int)msg.files;
                    for (int i = 0; i < msg.fileCount; i++)
                    {
                        Marshal.DestroyStructure((IntPtr)ptr,
                            typeof(MapiFileDesc));
                        ptr += size;
                    }
                    Marshal.FreeHGlobal(msg.files);
                }
     
                m_recipients.Clear();
                m_attachments.Clear();
                m_lastError = 0;
            }
     
            public string GetLastError()
            {
                if (m_lastError <= 26)
                    return errors[m_lastError];
                return "MAPI error [" + m_lastError.ToString() + "]";
            }
     
            readonly string[] errors = new string[] {
            "OK [0]", "User abort [1]", "General MAPI failure [2]", 
                    "MAPI login failure [3]", "Disk full [4]", 
                    "Insufficient memory [5]", "Access denied [6]", 
                    "-unknown- [7]", "Too many sessions [8]", 
                    "Too many files were specified [9]", 
                    "Too many recipients were specified [10]", 
                    "A specified attachment was not found [11]",
            "Attachment open failure [12]", 
                    "Attachment write failure [13]", "Unknown recipient [14]", 
                    "Bad recipient type [15]", "No messages [16]", 
                    "Invalid message [17]", "Text too large [18]", 
                    "Invalid session [19]", "Type not supported [20]", 
                    "A recipient was specified ambiguously [21]", 
                    "Message in use [22]", "Network failure [23]",
            "Invalid edit fields [24]", "Invalid recipients [25]", 
                    "Not supported [26]" 
            };
     
     
            List<MapiRecipDesc> m_recipients = new
                List<MapiRecipDesc>();
            List<string> m_attachments = new List<string>();
            int m_lastError = 0;
     
            const int MAPI_LOGON_UI = 0x00000001;
            const int MAPI_DIALOG = 0x00000008;
            const int maxAttachments = 20;
     
            enum HowTo { MAPI_ORIG = 0, MAPI_TO, MAPI_CC, MAPI_BCC };
        }
     
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        public class MapiMessage
        {
            public int reserved;
            public string subject;
            public string noteText;
            public string messageType;
            public string dateReceived;
            public string conversationID;
            public int flags;
            public IntPtr originator;
            public int recipCount;
            public IntPtr recips;
            public int fileCount;
            public IntPtr files;
        }
     
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        public class MapiFileDesc
        {
            public int reserved;
            public int flags;
            public int position;
            public string path;
            public string name;
            public IntPtr type;
        }
     
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        public class MapiRecipDesc
        {
            public int reserved;
            public int recipClass;
            public string name;
            public string address;
            public int eIDSize;
            public IntPtr entryID;
        }
     
    }
    C'est un genre de mailto en C#

  3. #3
    Membre émérite Avatar de Guulh
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    2 160
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2007
    Messages : 2 160
    Points : 2 925
    Points
    2 925
    Par défaut
    Hello,

    tu peux déjà exécuter le code en pas en à pas, et regarder le nom de l'Attachment juste après que tu l'ait ajouté, pour voir si le problème est causé par la création même de l'objet Attachment, ou s'il survient plus tard lors de l'envoi.

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    Citation Envoyé par bobjoumi Voir le message
    Bonjour, c'est surement pas ça que tu veux faire mais voila un classe qui pourrait être intéressante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
     
    using System;
    using System.Runtime.InteropServices;
    using System.IO;
    using System.Collections.Generic;
    using System.Windows.Forms;
     
     
    namespace Pgm
    {
        class MAIL
        {
     
            public bool AddRecipientTo(string email)
            {
                return AddRecipient(email, HowTo.MAPI_TO);
            }
     
            public bool AddRecipientCC(string email)
            {
                return AddRecipient(email, HowTo.MAPI_TO);
            }
     
            public bool AddRecipientBCC(string email)
            {
                return AddRecipient(email, HowTo.MAPI_TO);
            }
     
            public void AddAttachment(string strAttachmentFileName)
            {
                m_attachments.Add(strAttachmentFileName);
            }
     
            public int SendMailPopup(string strSubject, string strBody)
            {
                return SendMail(strSubject, strBody, MAPI_LOGON_UI | MAPI_DIALOG);
            }
     
            public int SendMailDirect(string strSubject, string strBody)
            {
                return SendMail(strSubject, strBody, MAPI_LOGON_UI);
            }
     
     
            [DllImport("MAPI32.DLL")]
            static extern int MAPISendMail(IntPtr sess, IntPtr hwnd,
                MapiMessage message, int flg, int rsv);
     
            int SendMail(string strSubject, string strBody, int how)
            {
                MapiMessage msg = new MapiMessage();
                msg.subject = strSubject;
                msg.noteText = strBody;
     
                msg.recips = GetRecipients(out msg.recipCount);
                msg.files = GetAttachments(out msg.fileCount);
     
                m_lastError = MAPISendMail(new IntPtr(0), new IntPtr(0), msg, how,
                    0);
                if (m_lastError > 1)
                    MessageBox.Show("MAPISendMail failed! " + GetLastError(),
                        "MAPISendMail");
     
                Cleanup(ref msg);
                return m_lastError;
            }
     
            bool AddRecipient(string email, HowTo howTo)
            {
                MapiRecipDesc recipient = new MapiRecipDesc();
     
                recipient.recipClass = (int)howTo;
                recipient.name = email;
                m_recipients.Add(recipient);
     
                return true;
            }
     
            IntPtr GetRecipients(out int recipCount)
            {
                recipCount = 0;
                if (m_recipients.Count == 0)
                    return IntPtr.Zero;
     
                int size = Marshal.SizeOf(typeof(MapiRecipDesc));
                IntPtr intPtr = Marshal.AllocHGlobal(m_recipients.Count * size);
     
                int ptr = (int)intPtr;
                foreach (MapiRecipDesc mapiDesc in m_recipients)
                {
                    Marshal.StructureToPtr(mapiDesc, (IntPtr)ptr, false);
                    ptr += size;
                }
     
                recipCount = m_recipients.Count;
                return intPtr;
            }
     
            IntPtr GetAttachments(out int fileCount)
            {
                fileCount = 0;
                if (m_attachments == null)
                    return IntPtr.Zero;
     
                if ((m_attachments.Count <= 0) | (m_attachments.Count >
                    maxAttachments))
                    return IntPtr.Zero;
     
                int size = Marshal.SizeOf(typeof(MapiFileDesc));
                IntPtr intPtr = Marshal.AllocHGlobal(m_attachments.Count * size);
     
                MapiFileDesc mapiFileDesc = new MapiFileDesc();
                mapiFileDesc.position = -1;
                int ptr = (int)intPtr;
     
                foreach (string strAttachment in m_attachments)
                {
                    mapiFileDesc.name = Path.GetFileName(strAttachment);
                    mapiFileDesc.path = strAttachment;
                    Marshal.StructureToPtr(mapiFileDesc, (IntPtr)ptr, false);
                    ptr += size;
                }
     
                fileCount = m_attachments.Count;
                return intPtr;
            }
     
            void Cleanup(ref MapiMessage msg)
            {
                int size = Marshal.SizeOf(typeof(MapiRecipDesc));
                int ptr = 0;
     
                if (msg.recips != IntPtr.Zero)
                {
                    ptr = (int)msg.recips;
                    for (int i = 0; i < msg.recipCount; i++)
                    {
                        Marshal.DestroyStructure((IntPtr)ptr,
                            typeof(MapiRecipDesc));
                        ptr += size;
                    }
                    Marshal.FreeHGlobal(msg.recips);
                }
     
                if (msg.files != IntPtr.Zero)
                {
                    size = Marshal.SizeOf(typeof(MapiFileDesc));
     
                    ptr = (int)msg.files;
                    for (int i = 0; i < msg.fileCount; i++)
                    {
                        Marshal.DestroyStructure((IntPtr)ptr,
                            typeof(MapiFileDesc));
                        ptr += size;
                    }
                    Marshal.FreeHGlobal(msg.files);
                }
     
                m_recipients.Clear();
                m_attachments.Clear();
                m_lastError = 0;
            }
     
            public string GetLastError()
            {
                if (m_lastError <= 26)
                    return errors[m_lastError];
                return "MAPI error [" + m_lastError.ToString() + "]";
            }
     
            readonly string[] errors = new string[] {
            "OK [0]", "User abort [1]", "General MAPI failure [2]", 
                    "MAPI login failure [3]", "Disk full [4]", 
                    "Insufficient memory [5]", "Access denied [6]", 
                    "-unknown- [7]", "Too many sessions [8]", 
                    "Too many files were specified [9]", 
                    "Too many recipients were specified [10]", 
                    "A specified attachment was not found [11]",
            "Attachment open failure [12]", 
                    "Attachment write failure [13]", "Unknown recipient [14]", 
                    "Bad recipient type [15]", "No messages [16]", 
                    "Invalid message [17]", "Text too large [18]", 
                    "Invalid session [19]", "Type not supported [20]", 
                    "A recipient was specified ambiguously [21]", 
                    "Message in use [22]", "Network failure [23]",
            "Invalid edit fields [24]", "Invalid recipients [25]", 
                    "Not supported [26]" 
            };
     
     
            List<MapiRecipDesc> m_recipients = new
                List<MapiRecipDesc>();
            List<string> m_attachments = new List<string>();
            int m_lastError = 0;
     
            const int MAPI_LOGON_UI = 0x00000001;
            const int MAPI_DIALOG = 0x00000008;
            const int maxAttachments = 20;
     
            enum HowTo { MAPI_ORIG = 0, MAPI_TO, MAPI_CC, MAPI_BCC };
        }
     
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        public class MapiMessage
        {
            public int reserved;
            public string subject;
            public string noteText;
            public string messageType;
            public string dateReceived;
            public string conversationID;
            public int flags;
            public IntPtr originator;
            public int recipCount;
            public IntPtr recips;
            public int fileCount;
            public IntPtr files;
        }
     
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        public class MapiFileDesc
        {
            public int reserved;
            public int flags;
            public int position;
            public string path;
            public string name;
            public IntPtr type;
        }
     
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        public class MapiRecipDesc
        {
            public int reserved;
            public int recipClass;
            public string name;
            public string address;
            public int eIDSize;
            public IntPtr entryID;
        }
     
    }
    C'est un genre de mailto en C#
    Merci pour ta réponse. En effet, si le problème provient du Framework () il faudra que j'utilise ta classe.

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    Citation Envoyé par Guulh Voir le message
    Hello,

    tu peux déjà exécuter le code en pas en à pas, et regarder le nom de l'Attachment juste après que tu l'ait ajouté, pour voir si le problème est causé par la création même de l'objet Attachment, ou s'il survient plus tard lors de l'envoi.
    Hello,
    J'ai pensé à cette solution après avoir envoyé mon message. Malheureusement, le résultat n'est pas concluant. Le nom du fichier apparaît correctement en debug.
    Ce qui est vraiment bizarre aussi, c'est que le contenu du fichier est codé en base64 dans le mail.

    Merci.

  6. #6
    Membre régulier Avatar de bobjoumi
    Profil pro
    Inscrit en
    Février 2009
    Messages
    94
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Février 2009
    Messages : 94
    Points : 86
    Points
    86
    Par défaut
    sinon faut préciser des trucs dans ton objet SmtpClient
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
                        SmtpClient smtp = new SmtpClient("serveur_smtp", 25);
                        //smtp.EnableSsl = true; si SSL
                        //smtp.Credentials = new NetworkCredential("Login", "password"); si authentification
    avec ça en plus j'ai envoyé ça comme pièce jointe :
    C:\serverscheck_databases\1171011122WINDOWSHEALTH.rrd

  7. #7
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    Citation Envoyé par bobjoumi Voir le message
    sinon faut préciser des trucs dans ton objet SmtpClient
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
                        SmtpClient smtp = new SmtpClient("serveur_smtp", 25);
                        //smtp.EnableSsl = true; si SSL
                        //smtp.Credentials = new NetworkCredential("Login", "password"); si authentification
    avec ça en plus j'ai envoyé ça comme pièce jointe :
    C:\serverscheck_databases\1171011122WINDOWSHEALTH.rrd
    Je vais essayer ça. Je te tiens au courant...

  8. #8
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    Citation Envoyé par bobjoumi Voir le message
    sinon faut préciser des trucs dans ton objet SmtpClient
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
                        SmtpClient smtp = new SmtpClient("serveur_smtp", 25);
                        //smtp.EnableSsl = true; si SSL
                        //smtp.Credentials = new NetworkCredential("Login", "password"); si authentification
    avec ça en plus j'ai envoyé ça comme pièce jointe :
    C:\serverscheck_databases\1171011122WINDOWSHEALTH.rrd
    J'ai essayé de spécifier le serveur SMTP explicitement mais, malheureusement, ça ne résout pas le problème.
    Par contre, avec le nom que tu utilises (1171011122WINDOWSHEALTH.rrd) tout se passe correctement.
    Le mystère reste entier. Y aurait-il une limite sur le nombre de caractères pour nom de fichier?

  9. #9
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    En approfondissant le problème, voici le constat auquel je suis arrivé.

    Quand on utilise le nom de fichier suivant :
    • Organisationdesinterrogatonsetexamensdejanvier2011premièreannée.doc --> pose problème
    • Organisationdesinterrogatonsetexamensdejanvier2011premiereannee.doc --> OK
    • premièreannée.doc --> OK
    • premiereannee.doc --> OK


    Il existe donc deux facteurs qui perturbent la transmission de la pièce jointe: les accents et un nom de fichier trop long. Lorsque ces deux facteurs sont réunis, la pièce jointe est illisible à la réception.
    Je me suis dit que le problème venait de l'encodage du nom (NameEncoding). J'ai donc essayé toutes les possibilités de la classe Encoding mais rien n'y fait .

  10. #10
    Membre émérite Avatar de Guulh
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    2 160
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2007
    Messages : 2 160
    Points : 2 925
    Points
    2 925
    Par défaut
    Citation Envoyé par sebagr Voir le message
    Il existe donc deux facteurs qui perturbent la transmission de la pièce jointe:
    A mon avis, seule la taille pose problème ; les accents peuvent prendre plus de place selon les encodages.
    As-tu aussi le même problème en enlevant les accents, mais en rajoutant une vingtaine de caractères par exemple ?

  11. #11
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    C'est bien ce que je pensais aussi. Mais ce qui m'interpelle c'est que le nom de fichier "Organisationdesinterrogatonsetexamensdejanvier2011premiereannee.doc" passe sans problème. Si on lui ajoute des accents, le problème survient.

  12. #12
    Membre régulier Avatar de bobjoumi
    Profil pro
    Inscrit en
    Février 2009
    Messages
    94
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Février 2009
    Messages : 94
    Points : 86
    Points
    86
    Par défaut
    Je me rappel d'un truc comme ça que j'ai déjà eu. Pour régler le problème j'ai tous mis en majuscule

  13. #13
    Membre régulier Avatar de bobjoumi
    Profil pro
    Inscrit en
    Février 2009
    Messages
    94
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Février 2009
    Messages : 94
    Points : 86
    Points
    86
    Par défaut
    Citation Envoyé par bobjoumi Voir le message
    Je me rappel d'un truc comme ça que j'ai déjà eu. Pour régler le problème j'ai tous mis en majuscule
    Je viens de tester en faite sa marche pas j'ai due faire d'autre chose...

  14. #14
    Membre régulier Avatar de bobjoumi
    Profil pro
    Inscrit en
    Février 2009
    Messages
    94
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Février 2009
    Messages : 94
    Points : 86
    Points
    86
    Par défaut
    je viens de trouver ça sur le net :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     
            public string RemoveDiacritics(string text)
            {
     
                return System.Text.Encoding.ASCII.GetString(System.Text.Encoding.GetEncoding(1251).GetBytes(text));
     
            }
    là je viens de tester, et ça marche bien. la méthode te supprime toutes l'accentuation. je me servais de ça pour faire des transfère en ftp sur un AS400.

  15. #15
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    Citation Envoyé par bobjoumi Voir le message
    Je viens de tester en faite sa marche pas j'ai due faire d'autre chose...
    Aucun problème
    Donc tu es arrivé à reproduire le problème. Ça me rassure à moitié.
    J'ai remarqué que le début du nom du fichier est codé en base 64 aussi.
    Par exemple, pour le fichier "Organisationdesinterrogatonsetexamensdejanvier2011premièreannée.doc"
    on obtient "=_utf-8_B_T3JnYW5pc2F0aW9uZGVzaW50ZXJyb2dh.dat" où T3JnYW5pc2F0aW9uZGVzaW50ZXJyb2dh = Organisationdesinterroga
    Je ne sais pas si ça peut aider pour trouver une solution.

  16. #16
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17
    Points : 11
    Points
    11
    Par défaut
    Merci pour votre aide.
    J'aurais bien aimé connaître la cause de ce problème mais je vais adopter la solution proposée par bobjoumi.

    A bientôt.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2003] Erreur lors d un envoi de pièce jointe
    Par wabo67 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 06/07/2010, 12h13
  2. Réponses: 4
    Dernier message: 09/06/2010, 17h44
  3. Pièces jointes illisibles
    Par couf35 dans le forum Général Python
    Réponses: 2
    Dernier message: 03/05/2010, 17h27
  4. Changement de navigateur lors de l'envoi d'un e-mail
    Par danielhagnoul dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 12/05/2009, 00h07
  5. [PHPMailer] Erreur lors d'un envoi d'un mail avec pièce jointe à destination de gmail
    Par arezki76 dans le forum Bibliothèques et frameworks
    Réponses: 15
    Dernier message: 14/08/2007, 18h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo