We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

URGENT: Need to set / override Return-Path

I've been using Aspose.Network (Version: to send bulk emails out and it's working great. I am now in a position where I need to process and analyze "bounced" email messages. I need to be able to set the MailMessage's Return-Path property to a value other than that of the sender's email address. (Ref: http://en.wikipedia.org/wiki/Bounce_message)

I do not see where this property can be set? I need this ability as soon as you can either A) show me where to set it or B) send out a patch with this ability.

Also, this property needs to be able to support Token replacement.

Please reply with a solution quickly.



Our developer is working on this requirement. We will provide new features to allow you to get/set the return path of an email message.

Best regards


Please try the following sample

MailMessage msg = MailMessage.Load(path);
MimeHeader h = msg.Headers["return-path"];
Console.Write(h.ToString());//read header value

//set header value
msg.Headers["return-path"] = new MimeHeader("return-path", "aaabounced2@godaddy.com");

Best regards

Thanks, but I still need the token replacement part. I need to insert a database identifier as part of the email address for the return-path.

Any estimated time to delivery for this capability?


Are you using TemplateEngine class with BulkSend() method for token replacements e.g. #Recipient#, #Subject# etc? And do you want this capability in return-path field?

If not, please provide some more details. After analyzing the requirement, we will be able to provide you the estimated time for the feature.

Exactly!!! I am using the TemplateEngine class and sending the emails with the BulkSend method. And YES, I am requesting token replacement for the Return-Path field as well.


Our developers are working on this issue. We will provide you the hotfix as soon as its resolved.

Any update as to when this feature will be available? If it will not be soon, then I will need to look at alternative solutions. A quick reply would be appreciated.

Thanks for considering Aspose.

I am sorry for not replying you timely.

Please check the attached hotfix. We have fixed this issue. Now you can replace the return-path as other fields in the mailmerge.

Let me know if it works. If you cannot get your code work, please also post your code here, I will help to investigate.

Best regards,

Thanks. I will test shortly. Do you also have the updated doc Aspose.Network.XML file?

Could you please provide a code sample? I do not see where the Return-Path parameter can be overridden? I have reflected the dll and do not see “Return-Path” as a property of the MailMessage object.

I have tested the new DLL (Version and it fails with the following exception in EVERY assembly that it is used in. Big problem.

When I revert back to DLL (Version the exception does not occur.

Stack Trace from the exception thrown from DLL (Version

at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style)
at System.DateTime.ParseExact(String s, String format, IFormatProvider provider)
at Aspose.Network.x220f433da4115056.x7d0214bf69711dd9(Stream xcf18e5243f8d5fd3)
at Aspose.Network.x220f433da4115056.x7d0214bf69711dd9(String x1c1fc72fe1a3b4ea, Assembly x5807f920b6fc67c4)
at Aspose.Network.License.SetLicense(String licenseName)
at <>.BusinessLayer.BusinessObjectBase..ctor() in C:\Development\<>\BusinessObjectBase.cs:line 85
at <>.BusinessLayer.EventRule..ctor(IEventRule data) in C:\<>\EventRule.cs:line 183
at <>.BusinessLayer.EventRule.Get(Guid ruleId) in C:\Development\<>\EventRule.cs:line 428
at <>.ManageRuleEmails.Page_Load(Object sender, EventArgs e) in C:\Development\<>\ManageRuleEmails.aspx.cs:line 45

Please use the following code sample to set the return-path header value of the message.

// remove the return-path, if it exists


// add new return-path header

msg.Headers["return-path"] = new MimeHeader("return-path", "#ReturnPath#");

Sorry for the inconvenience. We will fix this and send you the dll ASAP.


Please use the attached dll (ver. in your project. It contains the return-path and the exception fixes.

Getting closer. I am now receiving a System.FormatException error when executing the following code:

MailMessageCollection messages;

MailAddress fromAddress = new MailAddress("`[dgertz@mycompany.com](mailto:dgertz@mycompany.com)`", "`[dgertz@mycompany.com](mailto:dgertz@mycompany.com)`");

MailAddress toAddress = new MailAddress("#SendToEmailAddress#", true);

MailMessage message = new MailMessage(fromAddress, toAddress);


TemplateEngine engine = new TemplateEngine(message);
//Create the messages from the template and the datatable
messages = engine.Instantiate(<>);

When the engine.Instantiate method is called, the following exception occurs:

{“Invalid E-Mail Address Format:dgertz@mycompany.com <[dgertz@mycompany.com](mailto:dgertz@mycompany.com)>”}

Here is the stack trace:

at Aspose.Network.Mime.x3bb1e9025dbf40f4.x25437dba01d1e3b4(String x4a3f0a05c02f235f, Char xb25822984a90695b, Int32& x374ea4fe62468d0f, String& xf0d47d7698b4e263)
at Aspose.Network.Mime.x3bb1e9025dbf40f4.x2e577bdc8b34de50(String x4a3f0a05c02f235f, String& x179bb663e71b1f59, String& xf0d47d7698b4e263)
at Aspose.Network.Mail.MailAddress…ctor(String address)
at Aspose.Network.Mail.MailMessage.x7a127b6eb07f5b20(String x7446840b0e07b9b0, String xbcea506a33cf9111)
at Aspose.Network.Mail.TemplateEngine.Instantiate(DataTable table)
at <>.BusinessLayer.EmailProcessorWorker.OnDoWork(DoWorkEventArgs e) in C:\Development<>\EmailProcessorWorker.cs:line 335


Using tokens in object of type MailAddress is currently not supported. You can use following way to set such tokens in email addresses using string variables.

msg.To = "#RecipientMailAddress#";

Attached is a bulk mail sender sample that use such token replacements. Please let us know if this method suits for you or using MailAddress class is critical for your project.

Hello, dongertz,

Thanks for your information.

Please check the attached dll.

I have repro your bug according the code and call stack. It is caused by the issue in the element replace of the mail template engine. The display name of the FormAddress contains mail address ([dgertz@mycompany.com](mailto:dgertz@mycompany.com)), which may cause the template engine parse error.

Moreover, I have fixed it. Please check the attached dll, let me know if it works

The attached DLL is working as expected. I will let you know if there are any additional issues. Thank you for going the extra mile to implement a "better" solution.


I just tested the Return-Path Mime header option and it is NOT working. The Return-Path, in my case, I’m using to explicitly set the return email address for a message in order to route bounces to special addresses used for bounce processing.

As an example, a competitor ([www.quiksoft.com](http://www.quiksoft.com/)) (NOTE: I am not an employee of this company nor I’m I endorsing this product over Aspose !!! I am just using it as an example of functionality. )

If you download there EasyMail .Net Edition evaluation edition (http://www.quiksoft.com/services/dnetregistrations/reg.asp?prod=2100) and run the following code, you will see the behavior in action.

SMTP smtpObj = new SMTP();
EmailMessage mailMsg = new EmailMessage();
mailMsg.From.Email = "<>";
mailMsg.ReturnPath = "<>";

mailMsg.Subject = "Test for [nouser@gmail.com](mailto:nouser@gmail.com)";
mailMsg.BodyParts.Add("Test for [nouser@gmail.com](mailto:nouser@gmail.com)");

catch (Exception ex)
Console.WriteLine("Can't connect in to " + smtpObj.SMTPServers.Current.ToString() + "\nError: " + ex.Message);
if (ex.InnerException != null)
if (ex.InnerException.InnerException != null)


Then check the inbox for the email address specified in the Return-Path, you will see an “Undelivered Mail Returned to Sender” message from GMAIL’s MTA.

Please let me know if you can or can not reproduce my above example and if you can get the Aspose component to replicate this behavior.

On a side note, this is the ONLY issue that is preventing me from launching a new piece of functionality for the system I am working on and needs to be addressed/working and deployed very shortly. Any immediate help will be appreciated.