Free Support Forum - aspose.com

Special character in attendee email address of calendar

Am trying to save one calender with attendee !#$&@vitaexch.local

   Appointment f_objAppointment = null;
   MapiMessage f_objMapiMsg = null;

// creating calender
f_objAppointment = new Appointment(f_Location, null, f_Body, f_StartDate,
f_EndDate, null,
f_objMailAddressColl);

//assigning attendee !#$&@vitaexch.local andf getting mapimessege object
f_objAppointment.OptionalAttendees.Add("!#$&@vitaexch.local");
MailMessage f_objMsg = new MailMessage();
f_objMsg.AddAlternateView(f_objAppointment.RequestApointment()); // Here getting
exception
f_objMapiMsg = MapiMessage.FromMailMessage(f_objMsg);.

please check this case and let me know

@Shital_diwate,

Thank you for contacting Aspose support team.

I have tried following code using latest library Aspose.Email for .NET 18.3.0, but could not observe the issue. Could you please give it a try with the latest version and share the feedback?

Appointment f_objAppointment = null;
MapiMessage f_objMapiMsg = null;
MailAddressCollection f_objMailAddressColl = new MailAddressCollection();
f_objMailAddressColl.Add(new MailAddress("attendee1@gmail.com"));
f_objMailAddressColl.Add(new MailAddress("attendee2@gmail.com"));
f_objMailAddressColl.Add(new MailAddress("attendee3@gmail.com"));
// creating calender
f_objAppointment = new Appointment("f_Location", null, "f_Body", DateTime.Now, DateTime.Now.AddMinutes(30), null,f_objMailAddressColl);

//assigning attendee !#$&@vitaexch.local andf getting mapimessege object
f_objAppointment.OptionalAttendees.Add("!#$&@vitaexch.local");
MailMessage f_objMsg = new MailMessage();
f_objMsg.AddAlternateView(f_objAppointment.RequestApointment()); // Here getting exception
f_objMapiMsg = MapiMessage.FromMailMessage(f_objMsg);

Okay.
Now I copied all your above given code and checked with it and it is giving me same error.
We are also using 18.3
Please check in the following screenshots.

image.png (72.0 KB)

image.png (47.8 KB)

@Shital_diwate,

I have checked the scenario again and observed no issue as shown in the attached image. Complete project is attached here for your reference. Please give it a try and share the feedback.

ConsoleApp1.zip (10.8 KB)
image.png (49.7 KB)

In our side its working fine in few machine and in few machine its throwing exception.
We have tried with 32 and 64 bit machines and observed that its not depend on bit version as in one 64 bit its working and in other 64 bit it is not working.
We are not able to understand the root cause of this.

Can you try in different machine at your side to reproduce the issue ?

@Shital_diwate,

We have re-produced the issue by setting the project target framework to 4.5 or above. If target framework is set to 3.5, no exception is raised. This issue is logged under Id:EMAILNET-38967 for detailed analysis. We will write back here once analysis is completed and feedback is ready to share.

Okay.Somewhere at our end it reproduced with framework 4 also.
Please inform us imadiately once you have solution ready.

@Shital_diwate,

We have added this comment with the logged ticket for later reference. Thank you for the additional information.

is there any update here ?

@Shital_diwate,

In the .NET framework ver. 4 and later, System.Uri class constructor rises UriFormatException when host name specified in uri string (!#$&@vitaexch.local attendee in this case) is not valid. Because parsing rules are enabled by default. In earlier versions of the .NET Framework, the default value is false. In later versions of the .NET Framework, the default value is true, and the enabled state of parsing cannot be modified by settings in a .config file.
However, there is a workaround (maybe not safest) which uses reflection to substitute parser flags.

Please give a try to the following sample code and share the feedback.

ResetMailtoUriChecking();

Appointment f_objAppointment = null;
MapiMessage f_objMapiMsg = null;
...

public static void ResetMailtoUriChecking()
{
    System.Reflection.MethodInfo getSyntax = typeof(UriParser).GetMethod("GetSyntax", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
    System.Reflection.FieldInfo flagsField = typeof(UriParser).GetField("m_Flags", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

    if (getSyntax != null && flagsField != null)
    {
        foreach (string scheme in new[] { Uri.UriSchemeMailto })
        {
            UriParser parser = (UriParser)getSyntax.Invoke(null, new object[] { scheme });
            if (parser != null)
            {
                flagsField.SetValue(parser, 0);
            }
        }
    }
}