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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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!
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 ?