使用富文本框发送电子邮件正文?

时间:2012-06-15 19:45:33

标签: vb.net smtp rtf

我需要任何可以帮助我使用完整格式发送Richtextbox内容的代码。 我使用这段代码:

    Dim sendera As String = My.Settings.Sendermail
    Dim pass As String = My.Settings.Password
    Dim smtpServer As New SmtpClient()
    Dim mail As New MailMessage()
    smtpServer.Credentials = New Net.NetworkCredential(sendera, pass)
    smtpServer.Port = My.Settings.Port
    smtpServer.Host = My.Settings.SMTP
    smtpServer.EnableSsl = My.Settings.ESSL
    mail = New MailMessage()
    mail.From = New MailAddress(sendera)
    mail.To.Add(TextBox1.Text)
    mail.Subject = TextBox2.Text
    mail.IsBodyHtml = True
    mail.Body = RichTextBox1.Text
    smtpServer.Send(mail)

但当我发送电子邮件时,它显示为纯文本而没有任何格式化?

1 个答案:

答案 0 :(得分:1)

mailbody.Text.Replace(" ", "%20").Replace(vbNewLine, "%0A")
' %20 is url encoding for a space, %0A url encoding for new line

试试这个:
http://www.w3schools.com/tags/ref_urlencode.asp
祝你好运