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

Free Support Forum - aspose.com

Few questions about vcf

Hello,

  1. Any plan to add support for not-so-new VCardVersion 4.0 here?
    https://reference.aspose.com/email/net/aspose.email.personalinfo.vcard/vcardversion/

  2. I used the code sample at the bottom of this page to read .vcf contact and save to mht:
    https://docs.aspose.com/email/net/working-with-outlook-contacts/
    with these extra options:
    RenderedContactFields = Email.ContactFieldsSet.AllExisting
    and added:
    MhtFormatOptions = Email.MhtFormatOptions.WriteOutlineAttachments

But in the output, the contact photo is added as file attachment and not inside the mht/eml/mht, how can I force render it inside the mht? top-left / top-right?

  1. Notes section is rendered with different font, can force all parts to use a same font?

  2. How to add the email of contact file to the resulting mht/eml as From/To?
    Untitled.png (77.6 KB)

@australian.dev.nerds

Could you please attach your input VCF file, problematic and expected output MHTML here for testing? We will investigate the issue and provide you information on it.

Hello,
Surely it’s attached. ThanksFirst Middle Last Jr.zip (50.6 KB)

@australian.dev.nerds

Please also attach the problematic and expected output MHTML files here for our reference. We will investigate the issue and provide you more information on it.

Hello,
Thanks, attachedDesktop.zip (347.8 KB)

Can you also please kindly explain the details of:

Email.MhtFormatOptions.DisplayAsOutlook option?

Setting it will make no difference in my output mhtml

@australian.dev.nerds

We have logged this problem in our issue tracking system as EMAILNET-40724. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@australian.dev.nerds

Support for the VCardVersion 4.0 format has not been implemented due to its not prevalence. For example, Outlook saves contacts in the VERSION:2.1 format.

Outlook also does not render contact photos when saved in RTF. This feature is not supported by Aspose.Email.

Font settings for headers are set using CSS and can be cleared with a simple code. After that, all fonts will be the same.

mhtSaveOptions.CssStyles = mhtSaveOptions.CssStyles.Replace("font-weight:bold;", string.Empty)
                .Replace("font-family:\"Calibri\",\"sans-serif\";", string.Empty);

The email of contact rendered in Email header. The name of header “Email” may be renamed to “From/To” by simple code:

mhtSaveOptions.FormatTemplates[MhtTemplateName.Contact.Email] = mhtSaveOptions.FormatTemplates[MhtTemplateName.Contact.Email].Replace("Email", "From/To");

This option is make sense only for messages, not for Contact and Calendar. It provide rendering sender’s DisplayName only, without email address as it makes Outlook.

Hello,
Thanks for your help, if you don’t mind I’ve just some final questions:
When converting vcf vcard to message, I wanna get the email address of contact file and assign it to the sender of final eml message.
Please advise if I should look in Contact.ElectronicAddresses.DefaultEmailAddress or Contact.ElectronicAddresses.Email1?

Is it possible that Contact.ElectronicAddresses.Email2 or Contact.ElectronicAddresses.Email3 has an email address while Contact.ElectronicAddresses.Email1 does not have?
Or those three will be loaded in order so if there’s an email, must be in Contact.ElectronicAddresses.Email1…

Seems that Contact.ElectronicAddresses.DefaultEmailAddress will not be nothing, but a “N/A” string right? not the case about Contact.ElectronicAddresses.Email1

To assign that email address to the resulting msg or eml?
When saving Email.Mapi.MapiContact.Save(MSG, Email.Mapi.ContactSaveFormat.Msg)
or when saving as eml MSG.ToMailMessage(MyOptions)
setting MSG.SenderName = “sender name from above”
setting MSG.SenderEmailAddress = “sender email from above”
nothing happens!
Mail As Email.MailMessage = MSG.ToMailMessage(MyOptions)
Mail.From = “email from above”
also nothing happens!

@australian.dev.nerds

A ticket EMAILNET-40731 has been logged for your requirement. We will inform you once there is an update available on it.

Thanks, as you have noticed, I’m done with the small part of my development, just waiting for the open cases (fixes/ how tos) :frowning:

@australian.dev.nerds

You should look in Contact.ElectronicAddresses.Email1. The Contact.ElectronicAddresses.DefaultEmailAddress always contains “N/A” string if you don’t change it by yourself.

The answer is ‘No’.

These addresses is read in order, if VCF file contains one Email field then Contact.ElectronicAddresses.Email1 will be filled.

If VCF file contains three Email fields then first will be Email1, second - Email2, third - Email3.

Please use the following code example to populate the From field.

MapiContact contact = MapiContact.FromVCard("fds fsd fds fsdfds.vcf");
MemoryStream ms = new MemoryStream();
contact.Save(ms, ContactSaveFormat.Msg);
ms.Position = 0;
MapiMessage msg = MapiMessage.Load(ms);
MailConversionOptions op = new MailConversionOptions();
MailMessage eml = msg.ToMailMessage(op);
if(contact.ElectronicAddresses.Email1 != null)
    eml.From = new MailAddress(contact.ElectronicAddresses.Email1.EmailAddress);
eml.Save(fileName + ".eml");

Hello,
Thanks for the code snippet, this fixed the “From” field, but will save a blank Eml message

If I use:
eml.Save(fileName + “.eml” , MhtSaveOptions);

MhtSaveOptions.RenderedContactFields = Email.ContactFieldsSet.AllExisting
MhtSaveOptions.SaveAttachments = True
Dim MyFormatOptions As Email.MhtFormatOptions = Email.MhtFormatOptions.WriteHeader Or Email.MhtFormatOptions.RenderVCardInfo Or Email.MhtFormatOptions.WriteOutlineAttachments
MhtSaveOptions.MhtFormatOptions = MyFormatOptions

Adding WriteComplete(From)EmailAddress won’t help

The From field is lost, back to the 1st step :frowning:

I need to set MhtFormatOptions.WriteHeader + MhtFormatOptions.RenderVCardInfo + MhtFormatOptions.WriteOutlineAttachments which will clear the eml.From :frowning:

I’ve inspected the final result stream/file
This seems a bug in MailMessage not saving the From or Subject etc headers if we set those MhtFormatOptions

  • Even if we set “From” , “Subject” etc in the MapiMessage msg , still not being added to the final result

This completely removes the formatting (WriteHeader / RenderVCardInfo)
I meant apply the header font format to the rest of output message
In this case, make the Notes section’s font identical to the header.
My original snapshot:
https://forum.aspose.com/uploads/discourse_instance3/67882

@australian.dev.nerds

The MhtSaveOptions is used for MHTML file format. However, MailMessage.Save method saves the file to EML.

The code snippet you are using in this post is incorrect. So, the correct code was shared with you.

To ensure a timely and accurate response, please attach the following resources here for testing:

  • If you are not using ‘fds fsd fds fsdfds.vcf’ file, please share your input file.
  • Please attach the output file that shows the undesired behavior.
  • Please attach the expected output file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

The MhtSaveOptions is used for MHTML file format. However, MailMessage.Save method saves the file to EML.

Hello, AFAIK eml and mhtml are the same formats with different extensions, there can be minor fine tunes per extension though.

BTW, if you mean this is wrong:
eml.Save(fileName + “.eml” , MhtSaveOptions);

Does not seem so, because WriteHeader / RenderVCardInfo / WriteOutlineAttachments which all shapes the VCF to EML output, do not exist in EmlSaveOptions.

In addition, this is the way you’re using in your own sample here:

So I guess there’s a misunderstanding here…

@australian.dev.nerds

Please note that MhtSaveOptions class is used for MHTML save options and EmlSaveOptions class is used or EML save options.

You can share your sample input VCF along with expected output EML here for our reference. We will check the detail and provide you more information on it.

You are saving VCF to MHTML. In this case, you need to save the VCF to MSG file. Once you have the MSG file, you can apply all related properties of EmlSaveOptions or MhtSaveOptions to export the MSG to MHTML or EML.

We suggest you please save your VCF to MSG file first and let us know if there is any issue. If the MSG file is incorrect, the MHTML will not be as expected.

However, this is not vital for me, although would be nice :slight_smile:

Documents.zip (208.7 KB)