如何在Powershell中编码邮件主题?

时间:2015-08-28 08:17:16

标签: email powershell character-encoding smtp

我正在尝试使用带有日语字符的Powershell在邮件的主题和正文上发送邮件。邮件已成功发送,身体中的日文字符很好。但它不适用于主题。我得到了テスト而不是$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)

有人可以帮我吗?

<input name="id[]" value="1" />  <input name="st[]" value="4" />

<input name="id[]" value="5" />  <input name="st[]" value="57" />

<input name="id[]" value="79" /> <input name="st[]" value="43" />
                             .
                             .    
                             .

2 个答案:

答案 0 :(得分:2)

使用默认的CmdLet Send-MailMessage时,它适用于我:

$EmailParams = @{
    To          = 'Destination@domain.com'
    From        = 'From@domain.com'
    Subject     = 'テスト This is the subject'
    Body        = 'テスト This is the body'
    SMTPServer  = 'YourSMTPServer'
    Encoding    = 'UTF8'
}
Send-MailMessage @EmailParams

答案 1 :(得分:0)

我不知道怎么做。但它现在正在工作,我只是删除了主题的编码。

<强>码

$eSubject = "テスト This is subject"
$eBody = "テスト テスト テスト This is body"

$Encode = [Text.Encoding]::GetEncoding("csISO2022JP");

$Mail = New-Object Net.Mail.MailMessage("From@mail.com","To@mail.com")
$Mail.Subject = $eSubject

$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)