電子メールを非同期で送信しようとしていますが、電子メールにAlternateViewが添付されていない限り正常に動作します。代替ビューがある場合、私は次のエラーを取得する:.NET SMTP SendAsync with AlternateViewsが例外をスローしました
Dim msg As New System.Net.Mail.MailMessage
msg.From = New System.Net.Mail.MailAddress("[email protected]", "My Name")
msg.Subject = "email subject goes here"
'add the message bodies to the mail message
Dim hAV As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(textBody.ToString, Nothing, "text/plain")
hAV.TransferEncoding = Net.Mime.TransferEncoding.QuotedPrintable
msg.AlternateViews.Add(hAV)
Dim tAV As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(htmlBody.ToString, Nothing, "text/html")
tAV.TransferEncoding = Net.Mime.TransferEncoding.QuotedPrintable
msg.AlternateViews.Add(tAV)
Dim userState As Object = msg
Dim smtp As New System.Net.Mail.SmtpClient("emailServer")
'wire up the event for when the Async send is completed
AddHandler smtp.SendCompleted, AddressOf SmtpClient_OnCompleted
Try
smtp.SendAsync(msg, userState)
Catch '.... perform exception handling, etc...
End Try
とコールバック.....
Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
If e.Cancelled Then
'Log the cancelled error
End If
If Not IsNothing(e.Error) Then
'Log a real error....
' this is where the error is getting picked up
End If
'dispose the message
Dim msg As System.Net.Mail.MailMessage = DirectCast(e.UserState, System.Net.Mail.MailMessage)
msg.Dispose()
End Sub
HAV、HAVは、GCによって自動的に配置されているMSGオブジェクトのニーズが処分の参照..
乾杯を追加するということですマイクロソフトに提出してください。それが私をどこにでも連れて来るかどうかがわかります。 – hacker
マイクロソフトは返信し、エラーなく正常に動作させることができたことを示しました。私は電子メールの送信を非同期に再適用し、それをテストするために、そのアプリケーションに戻る機会はありませんでした。 – hacker