VB.NET Requires Chilkat v11.0.0+
VB.NET
Create a delivery failure report
See more Email Object Examples
A delivery agent can report a failure for an actual envelope recipient. Supply its observed SMTP outcome and enhanced status code, and return only the original headers when that is sufficient. This example saves a report for inspection. DSN format.
Chilkat VB.NET Downloads
Dim success As Boolean = False
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim email As New Chilkat.Email
success = email.LoadEml("message.eml")
If (success <> True) Then
Debug.WriteLine(email.LastErrorText)
Exit Sub
End If
Dim fields As New Chilkat.Xml
fields.Tag = "DeliveryStatusFields"
fields.NewChild2("Final-Recipient","rfc822; alex@example.net")
fields.NewChild2("Action","failed")
fields.NewChild2("Status","5.1.1")
fields.NewChild2("Diagnostic-Code","smtp; 550 5.1.1 Mailbox does not exist")
Dim report As New Chilkat.Email
success = email.ToDsn("The destination mailbox does not exist.",fields.GetXml(),True,report)
If (success <> True) Then
Debug.WriteLine(email.LastErrorText)
Exit Sub
End If
report.From = "Mail delivery agent <postmaster@example.net>"
' RFC 3464 puts the reporting MTA in its own block, ahead of the recipient fields.
Dim mimeBytes As New Chilkat.BinData
success = report.GetMimeBd(mimeBytes)
If (success <> True) Then
Debug.WriteLine(report.LastErrorText)
Exit Sub
End If
Dim mime As New Chilkat.Mime
success = mime.LoadMimeBd(mimeBytes)
If (success <> True) Then
Debug.WriteLine(mime.LastErrorText)
Exit Sub
End If
Dim statusPart As New Chilkat.Mime
success = mime.PartAt(1,statusPart)
If (success <> True) Then
Debug.WriteLine(mime.LastErrorText)
Exit Sub
End If
Dim status As New Chilkat.StringBuilder
status.Append("Reporting-MTA: dns; mx.example.net" & vbCrLf & vbCrLf)
status.Append(statusPart.GetBodyDecoded())
statusPart.SetBody(status.GetAsString())
success = mime.SaveMime("delivery-status.eml")
If (success <> True) Then
Debug.WriteLine(mime.LastErrorText)
Exit Sub
End If
Debug.WriteLine("Saved delivery-status.eml.")