Menu

How can I send an Email with unicode content

2008-06-11
2013-04-02
  • Tuấn Kiệt Trần

    I'm Vietnamese and I want to send email with Subject and Content in my language. But I can't do that with DotNetOpenMail. It appear with something like this "Ch? s? d? 3". Can anyone help me? Thanks!

     
    • nguyen hien

      nguyen hien - 2008-06-20

      you can try :

              Dim smg As New EmailMessage
              Dim smtpserver As New SmtpServer(Me.txt_SMTPServer.Text)
              Dim emailsTo As New EmailAddressCollection
              Dim emailsCC As New EmailAddressCollection
              Dim delim As Char = CChar(",")
              Dim fileAttachment As FileAttachment
              Dim readfile As StreamReader
              Dim Mail As String

              Dim bynaryReaderUtil As DotNetOpenMail.Utils.BinaryReaderUtil
              Dim bynaryReader As System.IO.BinaryReader
              Dim fs As System.IO.FileStream

              Try
                  Dim bytes_file As Byte()
                  If file_send.Value.ToString <> "" Then
                     

                      fs = New FileStream(file_send.Value.ToString, FileMode.Open)
                      bynaryReader = New System.IO.BinaryReader(fs)
                      bytes_file = bynaryReaderUtil.ReadIntoByteArray(bynaryReader)

                      fileAttachment = New FileAttachment(bytes_file)
                      fileAttachment.FileName = file_send.PostedFile.FileName
                      fileAttachment.ContentType = file_send.PostedFile.ContentType
                      smg.AddMixedAttachment(fileAttachment)
                  End If

                  smg.HeaderCharSet = System.Text.Encoding.GetEncoding("UTF-8")
                  smg.HeaderEncoding = DotNetOpenMail.Encoding.EncodingType.Base64
                  Set High Priority
                  smg.AddCustomHeader("X-Priority", "high")

                  smg.FromAddress = New EmailAddress(txt_mailfrom.Text)

                  If txt_mailto.Text <> "" Then
                      For Each Mail In txt_mailto.Text.Split(delim)
                          emailsTo.Add(New EmailAddress(Mail))
                      Next
                      smg.ToAddresses.AddCollection(emailsTo)
                  End If

                  If txt_CCs.Text <> "" Then
                      For Each Mail In txt_CCs.Text.Split(delim)
                          emailsCC.Add(New EmailAddress(Mail))
                      Next
                      smg.BccAddresses.AddCollection(emailsCC)
                  End If
                  smg.Subject = txt_subject.Text

                  ' Chuyen sang su dung kieu HtmlPart
                  smg.HtmlPart = New HtmlAttachment(txt_body.Text)
                  smg.HtmlPart.CharSet = System.Text.Encoding.GetEncoding("UTF-8")
                  smg.HtmlPart.Encoding = DotNetOpenMail.Encoding.EncodingType.Base64
                 
                
                  smg.Send(smtpserver)

                  Me.lb_erorr.Text = "Send mail successfull"
                  Me.lb_erorr.ForeColor = System.Drawing.Color.Blue

              Catch ex As Exception
                  Me.lb_erorr.Text = ex.ToString
                  Me.lb_erorr.ForeColor = System.Drawing.Color.Red
              End Try

      But i can`t display Subject with unicode ? I can`t fix this error. But Content Part work ok. Anyone help me ?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.