Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Create and Send an NDR (Non-Delivery Report)Download: Chilkat .NET Assemblies C# example code showing how to create and send an NDR email.
This code requires both Chilkat Mail and Chilkat Mime licenses. It is obviously complicated and Chilkat will be examining ways to simplify the creation of NDRs.
// Create and send a DSN (Delivery Status Notification) message // (also known as an NDR (non-delivery report) Chilkat.MailMan mailman = new Chilkat.MailMan(); mailman.UnlockComponent("Anything for 30-day trial"); // First, create a test email that will be used as the basis // for the NDR. Normally, this will be an email received by a server... Chilkat.Email rejectedEmail = new Chilkat.Email(); rejectedEmail.Subject = "This is my test email"; rejectedEmail.Body = "This is a test"; rejectedEmail.From = "support@chilkatsoft.com"; rejectedEmail.AddTo("mistermagoo","mistermagoo@chilkatsoft.com"); // We'll need to use Chilkat.Mime to create the NDR: Chilkat.Mime ndr = new Chilkat.Mime(); ndr.UnlockComponent("Anything for 30-day trial"); string fromAddr = rejectedEmail.FromAddress; string boundary = "--_44e45c00.1b5b.0+comcast.net=_"; string receivedTime = "17 Aug 2006 12:01:23 +0000"; string failedEmailAddr = rejectedEmail.GetToAddr(0); string failedEmailName = rejectedEmail.GetToName(0); string lastAttempt = "Thu, 17 Aug 2006 12:01:56 -0000"; ndr.AddHeaderField("content-type", "multipart/report; report-type=delivery-status; boundary=\"" + boundary + "\";"); Chilkat.Mime textPart = new Chilkat.Mime(); string textBody = @"A message (from <" + fromAddr + ">) was received at " + receivedTime + ".\n\nThe following addresses had delivery problems:\n\n" + "<" + failedEmailAddr + ">\n" + "\tPermanent Failure: 550_5.1.1_No_such_user_" + failedEmailName + "\n\tDelivery last attempted at " + lastAttempt + "\n"; textPart.SetBodyFromPlainText(textBody); ndr.AppendPart(textPart); Chilkat.Mime deliveryStatus = new Chilkat.Mime(); deliveryStatus.ContentType = "message/delivery-status"; // Note: This is a multi-line string literal: string devStatusBody = @"Reporting-MTA: dns; comcast.net Arrival-Date: 17 Aug 2006 12:01:23 +0000 Final-Recipient: rfc822; <FAILED_EMAIL_ADDR> Action: failed\ Status: 5.0.0 550_5.1.1_No_such_user_FAILED_EMAIL_NAME Diagnostic-Code: smtp; Permanent Failure: Other undefined Status Last-Attempt-Date: Thu, 17 Aug 2006 12:01:56 -0000"; devStatusBody = devStatusBody.Replace("FAILED_EMAIL_NAME",failedEmailName); devStatusBody = devStatusBody.Replace("FAILED_EMAIL_ADDR",failedEmailAddr); deliveryStatus.SetBodyFromBinary(Encoding.ASCII.GetBytes(devStatusBody)); deliveryStatus.Encoding = ""; ndr.AppendPart(deliveryStatus); Chilkat.Mime rfc822Msg = new Chilkat.Mime(); rfc822Msg.NewMessageRfc822(rejectedEmail.GetMimeObject()); ndr.AppendPart(rfc822Msg); // Add the outer-layer header fields. ndr.AddHeaderField("Subject","Returned mail: delivery problems encountered"); ndr.AddHeaderField("To",fromAddr); ndr.AddHeaderField("From","Mail Delivery Subsystem <mailer-daemon@chilkatsoft.com>"); ndr.AddHeaderField("Message-Id","<20060817120728m15006qr00e@A@000000000000@comcast.net>"); ndr.AddHeaderField("Date","13 Nov 2006 12:07:28 +0000"); ndr.AddHeaderField("MIME-Version","1.0"); ndr.SaveMime("ndr.eml"); MessageBox.Show(ndr.GetMime()); mailman.SmtpHost = "smtp.comcast.net"; bool success = mailman.SendMime("mailer-daemon@chilkatsoft.com",fromAddr,ndr.GetMime()); if (!success) { mailman.SaveLastError("sendMimeError.txt"); MessageBox.Show("SendMime failed!"); } else { MessageBox.Show("SendMime success!"); } Important: The download for this
example does not contain the ChilkatDotNet.dll which |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.