如何防止电子邮件发送中的强格式丢失? [英] How to prevent strong formatting lose in Email send?

查看:85
本文介绍了如何防止电子邮件发送中的强格式丢失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不能弄明白。



我有一个MailMessage消息。



我正在尝试使用EmailClient.Send(msg)发送电子邮件。我不工作,但是,在电子邮件正文中,我有几个新行(\ n)并且它们没有转移到我的电子邮件消息。而不是普通的电子邮件,我得到一行文字,也没有\ n - 他们只是消失了。



我怎样才能防止这个事情发生一个普通的电子邮件新行?

解决方案

使用System.Net; 
使用System.Net.Mail;
使用System.Net.Mime;

private void button1_Click(object sender,EventArgs e)
{
SmtpClient Smtp = new SmtpClient(smtp.gmail.com,587); // SMTP服务器和端口号
Smtp.Credentials = new NetworkCredential(yourmail@gmail.com,password);
Smtp.EnableSsl = true;
MailMessage Message = new MailMessage();
Message.From =新邮件地址(yourmail@gmail.com,发件人名称,Encoding.UTF8);
Message.To.Add(new MailAddress(abc@abc.com));
Message.Subject =新消息;
Message.SubjectEncoding = Encoding.UTF8;
Message.Body =Message text\\\
123\\\
456\\\
789;
Smtp.Send(留言);
}





结果:



留言文字

123

456

789




Cant figure it out.

I have a MailMessage msg.

I am trying to send email by using EmailClient.Send(msg). I't working but, in email body I nave a several new lines (\n) and they are not transferred to my email message. Instead of normal email, I am getting a single line with text, and also without \n - they are simply disappeared.

How can I prevent this thing and get a normal email with new lines?

解决方案

using System.Net;
using System.Net.Mail;
using System.Net.Mime;

        private void button1_Click(object sender, EventArgs e)
        {
            SmtpClient Smtp = new SmtpClient("smtp.gmail.com", 587); //SMTP server and port number
            Smtp.Credentials = new NetworkCredential("yourmail@gmail.com", "password");
            Smtp.EnableSsl = true;
            MailMessage Message = new MailMessage();
            Message.From = new MailAddress("yourmail@gmail.com", "Sender Name", Encoding.UTF8);
            Message.To.Add(new MailAddress("abc@abc.com"));
            Message.Subject = "New Message";
            Message.SubjectEncoding = Encoding.UTF8;
            Message.Body = "Message text\n123\n456\n789";
            Smtp.Send(Message);
        }



The result:

Message text
123
456
789


这篇关于如何防止电子邮件发送中的强格式丢失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆