title: How to encode the subject of the mail in Powershell?
body: <p>I am trying to send mail using Powershell with Japanese character on the subject and body of the mail. The mail is successfully sent and the Japanese character in the body is fine. But it is not working in subject. I got <code>=?iso-2022-jp?Q?=1B=24B=25F=259=25H=1B=28B?=</code> instead of <code>テスト</code>.</p>
  
  <p>Can someone help me on this?</p>
  
  <p><strong>code</strong>:</p>
  
  <pre><code>$eSubject = "テスト This is subject"
  $eBody = "テスト テスト テスト This is body"
  
  $Encode = [Text.Encoding]::GetEncoding("csISO2022JP");
  $s64 = [Convert]::ToBase64String($Encode.GetBytes($eSubject), [Base64FormattingOptions]::None)
  
  $Mail = New-Object Net.Mail.MailMessage("From@mail.com","To@mail.com")
  $Mail.Subject = [String]::Format("=?{0}?B?{1}?=", $Encode.HeaderName, $s64)
  
  $View = [Net.Mail.AlternateView]::CreateAlternateViewFromString($eBody, $Encode, [Net.Mime.MediaTypeNames]::Text.Plain)
  $View.TransferEncoding = [Net.Mime.TransferEncoding]::SevenBit
  $Mail.AlternateViews.Add($View)
  
  $SmtpClient = NEW-OBJECT Net.Mail.SmtpClient("localhost","25")
  $SmtpClient.Send($Mail)
  </code></pre>