AttachmentIsVCard Property |
Namespace: MailBee.Mime
The samples below utilize vCard functionality provided by a separate .DLL. To proceed, you should add a reference to ICalVCard.dll to your project.
You can find ICalVCard.dll in the same folder as MailBee.NET.dll (such as "C:\Program Files\MailBee.NET Objects\2.0").
To read more on ICalVCard.dll, view or download its documentation or source code, navigate to https://afterlogic.com/mailbee-net/icalvcard.
You can also refer to iCal and vCard Developer's Guide for sample code and further explanations.
You do not need any license keys to use ICalVCard.dll, it's a free library. Moreover, the full source code is available.
This topic contains several examples.
The first sample loads the message from an .EML file (it's assumed the message has a vCard attachment) and displays several fields from the vCard user profile.
using System; using MailBee.Mime; using vCards; class Sample { static void Main(string[] args) { MailMessage msg = new MailMessage(); msg.LoadMessage(@"C:\Docs\vcard.eml"); foreach (Attachment attach in msg.Attachments) { if (attach.IsVCard) { vCard crd = new vCard(attach.GetData()); Console.WriteLine("Name: " + crd.FormattedName); Console.WriteLine("Title: " + crd.Title); Console.WriteLine("BirthDate: " + crd.BirthDate); Console.WriteLine("Organization: " + crd.Organization); foreach (vCardPhone phone in crd.Phones) { if (phone.IsCellular) { Console.WriteLine("Cellular phone number: " + phone.FullNumber); } else if (phone.IsHome) { Console.WriteLine("Home phone number: " + phone.FullNumber); } else if (phone.IsWork) { Console.WriteLine("Work phone number: " + phone.FullNumber); } else if (phone.IsFax) { Console.WriteLine("Fax number: " + phone.FullNumber); } } } } } }
using System; using System.IO; using System.Text; using MailBee.Mime; using MailBee.SmtpMail; using vCards; class Sample { static void Main(string[] args) { // Create a new user profile. vCard crd = new vCard(); crd.GivenName = "John"; crd.FamilyName = "Smith"; crd.Gender = vCardGender.Male; crd.BirthDate = new DateTime(1980, 3, 2); crd.Phones.Add(new vCardPhone("123-456-789", vCardPhoneTypes.Cellular)); crd.Phones.Add(new vCardPhone("893-111-789", vCardPhoneTypes.Home)); crd.Phones.Add(new vCardPhone("222-555-333", vCardPhoneTypes.Work)); vCardPhoto photo = new vCardPhoto(@"C:\Docs\john_smith.jpg"); crd.Photos.Add(photo); MailMessage msg = new MailMessage(); msg.From.AsString = "user@mail.com"; msg.To.Add("newuser@mail.com"); msg.Subject = "See attached vCard"; vCardStandardWriter wrt = new vCardStandardWriter(); StringWriter sw = new StringWriter(); // Specify charset to encode non-ascii strings. wrt.Write(crd, sw, "windows-1252"); // Add vCard as attachment. msg.Attachments.Add( Encoding.GetEncoding("windows-1252").GetBytes(sw.ToString()), "John Smith.vcf", null, "application/octet-stream", null, NewAttachmentOptions.None, MailTransferEncoding.QuotedPrintable); // And send it. Smtp.QuickSend(msg); } }
using MailBee.Mime; using vCards; MailMessage msg = new MailMessage(); msg.LoadMessage(@"C:\Docs\vCardWithPhoto.eml"); foreach (Attachment attach in msg.Attachments) { if (attach.IsVCard) { vCard crd = new vCard(attach.GetData()); label1.Text = crd.GivenName; label2.Text = crd.FamilyName; pictureBox1.Image = Image.FromStream( new MemoryStream(crd.Photos[0].GetBytes())); } }