Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

December 21, 2007

Send Japanese Email in VB.NET

This example demonstrates sending Japanese email in VB.NET:

	
    Private Sub JapaneseEmail()
	
        ' This example loads Japanese text from a file, and uses it as
        ' both the subject and body and sends an email.
	
        ' The sample data can be downloaded from:
        ' http://www.chilkatsoft.com/testData/japanese_utf8.txt
	
        ' First, read the bytes into memory.  We'll read it as bytes
        ' and then convert from utf-8 bytes to a string:
        Dim utf8Bytes() As Byte
        utf8Bytes = System.IO.File.ReadAllBytes("japanese_utf8.txt")
	
        Dim japaneseStr As String
        japaneseStr = System.Text.UTF8Encoding.UTF8.GetString(utf8Bytes)
	
        ' If our string is valid, it should display properly in a message box.
        ' Make sure you verify this first.  VB.NET and C# programs should be
        ' capable of displaying any language.
        MessageBox.Show(japaneseStr)
	
        ' Create a mailman for sending, then create an email with this
        ' Japanese text in body and subject:
        Dim mailman As New Chilkat.MailMan()
        Dim success As Boolean
	
        success = mailman.UnlockComponent("Anything for 30-day trial")
        If (Not success) Then
            MessageBox.Show("Failed to unlock email component")
            Exit Sub
        End If
	
        mailman.SmtpHost = "mail.chilkatsoft.com"
        mailman.SmtpUsername = "****"
        mailman.SmtpPassword = "***"
	
        Dim email As New Chilkat.Email()
        email.Subject = japaneseStr
        email.Body = japaneseStr
	
        email.From = "support@chilkatsoft.com"
        email.AddTo("Chilkat Admin", "admin@chilkatsoft.com")
	
        ' By default, Chilkat recognizes the Japanese characters when
        ' the Subject and Body properties were set, and the charset
        ' was automatically set to the most appropriate charset
        ' for Japanese email: shift_jis
	
        success = mailman.SendEmail(email)
        If (Not success) Then
            MessageBox.Show(mailman.LastErrorText)
            Exit Sub
        End If
	
        ' You may choose another charset by setting the Email.Charset property.
        ' This causes all parts of the email (header fields and body) to use
        ' the new charset.
        email.Charset = "utf-8"
	
        ' Send it again, this time using utf-8.
        success = mailman.SendEmail(email)
        If (Not success) Then
            MessageBox.Show(mailman.LastErrorText)
            Exit Sub
        End If
	
        ' Here's yet another choice for Japanese email: iso-2022-jp:
        email.Charset = "iso-2022-jp"
	
        ' Send it again, this time using iso-2022-jp.
        success = mailman.SendEmail(email)
        If (Not success) Then
            MessageBox.Show(mailman.LastErrorText)
            Exit Sub
        End If
	
        ' Now let's say you want to send HTML email.
        ' If a charset is specified in the HTML, it better match the charset
        ' you're using:
        email.Charset = "utf-8"
	
        Dim html As String
        html = "<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">"
        html = html + "</head><body><b>"
        html = html + japaneseStr + "</b></body></html>"
	
        email.AddHtmlAlternativeBody(html)
        email.AddPlainTextAlternativeBody(japaneseStr)
	
        ' Now send the email, which has both plain-text and HTML alternative
        ' bodies:
        success = mailman.SendEmail(email)
        If (Not success) Then
            MessageBox.Show(mailman.LastErrorText)
            Exit Sub
        End If
	
        MessageBox.Show("Mail sent!")
	
    End Sub


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.