发送邮件方法的问题

时间:2011-07-07 21:51:29

标签: c# email send

在这种方法中我发送邮件

        var mail = new MailMessage();

        mail.Subject = subject;
        mail.SubjectEncoding = Encoding.UTF8;

        mail.IsBodyHtml = mailServer.EsHtml;

        mail.From = new MailAddress(mailFrom, nomFrom,Encoding.UTF8);

        foreach(var item in mailTo)
            mail.To.Add(new MailAddress(item.Key, item.Value, Encoding.UTF8));

        foreach(var item in mailCC)
            mail.Bcc.Add(new MailAddress(item.Key, item.Value, Encoding.UTF8));

        mail.Body = message;
        mail.BodyEncoding = Encoding.Unicode;

        mail.Attachments.Add(new Attachment(attachments));

        var clientMail = new SmtpClient();

        clientMail.Credentials = new System.Net.NetworkCredential(mailFrom, passMail);

        if(mailServer.PuertoCorreo.HasValue)
            clientMail.Port = mailServer.PuertoCorreo.Value;

        clientMail.Host = mailServer.ServidorCorreo;

        clientMail.EnableSsl = mailServer.HabilitarSSL;

        clientMail.Send(mail);

它工作正常,但在身体的gmail中,我得到了这个text਍猀搀搀昀ഀ more text和附加名称的hotmail我得到了这个牰敵慢瀮晤。方法有什么问题?

1 个答案:

答案 0 :(得分:0)

试试这个:

mail.BodyEncoding = System.Text.Encoding.UTF8;