掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
VB2010 メール送信 添付ファイル名文字化け (ID:147716)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
自己レスです。 http://msdn.microsoft.com/ja-jp/library/system.net.mail.attachment%28v=vs.80%29.aspx を参考にエラー発生しないコードにしてメール送信だけはできるようにしました。 下記にすると添付ファイル名が化けます。 エンコードしたファイル名はどう使えば良いのかアドバイス戴ければ幸いです。 Public Sub CreateMessageWithAttachment(ByVal server As String) Dim file As String = "ほげほげ.xls" 'Create a message and set up the recipients. Dim message As MailMessage = _ New MailMessage( _ "jane@contoso.com", _ "ben@contoso.com", _ "Quarterly data report.", _ "See the attached spreadsheet.") 'Create the file attachment for this e-mail message. Dim data As Attachment = New Attachment(file, MediaTypeNames.Application.Octet) Dim disposition As ContentDisposition = data.ContentDisposition disposition.FileName = EncordB(file) 'Add the file attachment to this e-mail message. message.Attachments.Add(data) 'Send the message. Dim client As SmtpClient = New SmtpClient(server) 'Add credentials if the SMTP server requires them. client.Send(message) data.Dispose() End Sub Private Function EncordB(ByVal strTarget As String) As String Dim arrbJisSubject() As Byte ' iso-2022-jp に変換した件名 Dim strEncSubject As String ' B エンコードした件名 ' 件名を iso-2022-jp に変換します。 arrbJisSubject = System.Text.ASCIIEncoding.GetEncoding("iso-2022-jp").GetBytes(strTarget) ' iso-2022-jp に変換した文字列を Base64 エンコードし、エンコードを表す文字列を追加します。 strEncSubject = "=?ISO-2022-JP?B?" & Convert.ToBase64String(arrbJisSubject) & "?=" Return strEncSubject End Function
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.