?
Solved

Delivery Notification through C# 1.1

Posted on 2009-02-23
14
Medium Priority
?
6,098 Views
Last Modified: 2013-12-17
I want to receive a delivery notification when sending an email through ASP.NET 1.1 C#.

I can get a read notification using;
testMessage.Headers.Add("disposition-notification-to", txtFrom.Text);

However I cannot get a delivery notification. I have tried;
testMessage.Headers.Add("Return-Receipt-To", txtFrom.Text);
and/or
testMessage.Fields.Add("urn:schemas:mailheader:return-receipt-to", txtFrom.Text);

Neither work.

I am sending from domain 1 to domain 2. They are not linked in anyway. Manually (through outlook) sending an email with request delivery notification selected works perfectly from domain 1 to domain 2. However when I create and send the same email through a windows/ASP.NET application no delivery notification is returned.

I know this is made much simpler in .Net 2.0+. But that isn't an option with this application. Does anyone have a solution to this issue?
System.Web.Mail.MailMessage testMessage = new System.Web.Mail.MailMessage();
				System.Web.Mail.SmtpMail.SmtpServer = txtSMTP.Text;
			
				testMessage.To = txtTo.Text;
				testMessage.From = txtFrom.Text;
				testMessage.Subject = txtSubject.Text;
				testMessage.Body = txtBody.Text;
				testMessage.BodyFormat = System.Web.Mail.MailFormat.Text;
				if(chkDelivery.Checked)
				{//Not Working! :-(
					testMessage.Headers.Add("Return-Receipt-To", txtFrom.Text);
					//testMessage.Fields.Add("urn:schemas:mailheader:return-receipt-to", txtFrom.Text);
				}
				if(chkRead.Checked)
				{
					testMessage.Headers.Add("disposition-notification-to", txtFrom.Text);
				}
				System.Web.Mail.SmtpMail.Send(testMessage);

Open in new window

0
Comment
Question by:AshleighGreen
  • 9
  • 5
14 Comments
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23716855
Reading up on the System.Web.Mail, I noticed it is just a wrapper class for CDOSYS, but I don't see any way to get to the DSNOptions which is what you want to modify.

'    cdoDSNDefault             0       No DSN commands are issued.
'    cdoDSNNever               1       No DSN commands are issued.
'    cdoDSNFailure             2       Return a DSN if delivery fails.
'    cdoDSNSuccess             4       Return a DSN if delivery succeeds.
'    cdoDSNDelay               8       Return a DSN if delivery is delayed.
'    cdoDSNSuccessFailOrDelay  14      Return a DSN if delivery succeeds, fails, or is delayed.

I'll keep digging and see if I can find something useful.
0
 
LVL 2

Author Comment

by:AshleighGreen
ID: 23717026
Hello aibusinesssolutions,

Thanks for the quick reply. Yes, I did see a number of articles talking about the DSNOptions when sending through ASP flat. I have, as yet, been unsuccessful in finding a way to modify the DSNOption. I was also considering if it would be better to just access the CDO.Message object directly, and bypass using the System.Web.Mail wrapper, however I haven't found any good examples of how to do that either.

I'm looking forward to the results of your further digging,
-Ashleigh
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23717039
Here is an example of using the CDO, I'm sure it can be modified to work with asp.net 1.1

http://support.microsoft.com/default.aspx?scid=kb;en-us;302839
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:AshleighGreen
ID: 23717087
Hey,

I have seen that example for asp, however am unsure of how to convert that into c#.
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23717126
Well, before you do that, did you check the headers of the email in your email client?  

I just tried msg.Headers.Add("Return-Receipt-To", "xxxx@xxxx.com");
and got this, also the checkbox saying a delivery receipt was request was checked.. but I never got a delivery notification.

Return-Receipt-To: <xxxx@xxxx.com>
From: <xxxx@xxxx.com>
To: <xxxx@xxxx.com>
Date: Mon, 23 Feb 2009 19:00:26 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.1.7000.0
Return-Path: xxxx@xxxx.com
X-MS-Exchange-Organization-SCL: 0
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23717185
And this is what it looks like when I do it through Outlook, and I DO get a delivery receipt with this.

From: xxxxx <xxxx@xxxx.com>
To: xxxxx <xxxx@xxxx.com>
Return-Receipt-To: <xxxx@xxxx.com>
Date: Mon, 23 Feb 2009 18:09:14 -0600
Subject: test
Thread-Topic: test
Thread-Index: AcmWFCBDJO3OadtNSAO0hyaRsu9O/w==
Message-ID: <20F36FA53D393246A84B0B2E420DB3876BA5DCFC59@xxxx.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-Exchange-Organization-SCL: -1
X-MS-TNEF-Correlator: <20F36FA53D393246A84B0B2E420DB3876BA5DCFC59@xxxx.com>
MIME-Version: 1.0
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23717246
Well I tried adding different headers in, and it doesn't seem to work regardless, I think you're just going to have to use the CDOSYS.
0
 
LVL 2

Author Comment

by:AshleighGreen
ID: 23717257
Hey,

I have checked that. I've also looked at what the headers are like in 2.0 where delivery receipt is an option. Interestingly they look like this;

MIME-Version: 1.0
From: <XXXXX@XXXX>
To: <XXXXX@XXXXXXXXXXX>
Date: Tue, 24 Feb 2009 10:08:23 +1030
Subject: Testing Delivery Receipt 2.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Return-Path: XXXXX@XXXXXX
Message-ID: <XXXZhCl8aii08N8y0000018c@XXXXXX>

It worked, and there isn't even a Return-Receipt-To.
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23717270
Here's something on using CDOSYS in C#.  It's for checking mail in the drop directory, but it'll get you started.
0
 
LVL 2

Author Comment

by:AshleighGreen
ID: 23717304
Yes, I am coming to that conclusion also. But I am unsure of how to use the CDOSYS in C#.
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23717367
It's really weird, I got the example working in C#, but when I set the DSNOptions I never get the email.
0
 
LVL 15

Accepted Solution

by:
aibusinesssolutions earned 2000 total points
ID: 23717444
Here's the code, make sure you reference Microsoft CDO, and add a using CDO;

If you remark out the DSNOptions line, it seems to work fine for me, but when I set it I never get the email.
Message msg = new Message();
Configuration conf = new Configuration();
 
conf.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
conf.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = "mail.domain.com";
conf.Fields.Update();
 
msg.Configuration = conf;
msg.Fields["urn:schemas:mailheader:disposition-notification-to"].Value = "xxx@xxxx.com";
msg.Fields["urn:schemas:mailheader:return-receipt-to"].Value = "xxx@xxxx.com";
msg.To = "xxx@xxxx.com";
msg.From = "xxx@xxxx.com";            
msg.Subject = "test";
msg.TextBody = "test";
msg.DSNOptions = CdoDSNOptions.cdoDSNSuccessFailOrDelay;
msg.Fields.Update();
 
msg.Send();

Open in new window

0
 
LVL 2

Author Closing Comment

by:AshleighGreen
ID: 31550371
Thanks,

This worked perfectly. It sent the message fine, and the message contained the delivery notification worked. The read notification also worked fine.

As a note to anyone else who may come across this solution. The file to reference was c:\windows\system32\cdosys.dll

Thanks heaps for your help.
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23717663
I was using SMTP authentication with that example, so that may be why it wasn't working for me. Glad I could help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question