10-03-2008 11:17 AM - edited 10-03-2008 11:18 AM
I need to programmatically send a contact as a VCard attachment via email.
Referring to the KB Article DB-00009 "How to - Create an Attachment" I have implemented this succcessfully on 4.2. However, the same code fails on 4.5 when the Message object is passed to the Messages application via Invoke().
The message displayed by the Email program is: "Email service does not support these types of attachments. Change the Send-Using field, or change the attachments".
I tried setting the following content types with no-joy:
"text/x-vcard" (the correct MIME type for this attachment)
BodyPart.ContentType.TYPE_ADDRESS_BOOK_STRING
BodyPart.ContentType.TYPE_TEXT + bodyPart.ContentType.SUBTYPE_X_RIMDEVICE_ADDRESS_B
BodyPart.ContentType.TYPE_APPLICATION + BodyPart.ContentType.SUBTYPE_X_RIMDEVICE_ADDRESS_B
Has anyone else seen this issue?
Is there an updated version of the KB article somewhere that describes how this was changed for OS 4.5?
Solved! Go to Solution.
10-03-2008 11:47 AM
Ooops...answered my own question.
See PDAPContactAttachmentPart
03-19-2010 04:19 PM
Hi Rex,
I'm facing the same problem with your previous message. And I'm still having problem with this. Could you give me some snippet?
Here is my code:
Multipart multipart = new Multipart();
PDAPContactAttachmentPart vcard = new PDAPContactAttachmentPart(multipart);
ContactList contacts = null;
try {
contacts = (ContactList) PIM.getInstance().openPIMList(
PIM.CONTACT_LIST, PIM.READ_WRITE);
Contact contact = contacts.createContact();
String[] fieldName = new String[contacts.stringArraySize(Contact.NAME)];
if (contacts.isSupportedField(Contact.FORMATTED_NAME) )
contact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE, cont.getElement(MontroseContact.BUSINESS_NAME));
// contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, fieldName);
if (contacts.isSupportedField(Contact.TEL))
contact.addString(Contact.TEL, Contact.ATTR_WORK, cont.getElement(MontroseContact.PHONE_NUMBER));
vcard.setContent(contact);
String[] data_formats = PIM.getInstance().supportedSerialFormats(
PIM.CONTACT_LIST );
ByteArrayOutputStream os = new ByteArrayOutputStream();
PIM.getInstance().toSerialFormat( contact, os, "UTF-8", data_formats[ 0 ] );
SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart, "text/x-vcard", "contact.vcf", os.toByteArray());
multipart.addBodyPart(attach);
Store store = Session.getDefaultInstance().getStore();
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder = folders[0];
Message message = new Message(sentfolder);
message.setContent(multipart);
message.setSubject("Contact - "+cont.getElement(MontroseContact.BUSINESS_NAME));
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
new MessageArguments(message));
} catch (PIMException e) {
throw new Exception(e.getMessage());
}Thanks in advance.
03-19-2010 04:45 PM
Hi Rex,
I'm facing the same problem with your previous message. And I'm still having problem with this. Could you give me some snippet?
Here is my code:
Multipart multipart = new Multipart();
PDAPContactAttachmentPart vcard = new PDAPContactAttachmentPart(multipart);
ContactList contacts = null;
try {
contacts = (ContactList) PIM.getInstance().openPIMList(
PIM.CONTACT_LIST, PIM.READ_WRITE);
Contact contact = contacts.createContact();
String[] fieldName = new String[contacts.stringArraySize(Contact.NAME)];
if (contacts.isSupportedField(Contact.FORMATTED_NAME) )
contact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE, cont.getElement(MontroseContact.BUSINESS_NAME));
// contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, fieldName);
if (contacts.isSupportedField(Contact.TEL))
contact.addString(Contact.TEL, Contact.ATTR_WORK, cont.getElement(MontroseContact.PHONE_NUMBER));
vcard.setContent(contact);
String[] data_formats = PIM.getInstance().supportedSerialFormats(
PIM.CONTACT_LIST );
ByteArrayOutputStream os = new ByteArrayOutputStream();
PIM.getInstance().toSerialFormat( contact, os, "UTF-8", data_formats[ 0 ] );
SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart, "text/x-vcard", "contact.vcf", os.toByteArray());
multipart.addBodyPart(attach);
Store store = Session.getDefaultInstance().getStore();
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder = folders[0];
Message message = new Message(sentfolder);
message.setContent(multipart);
message.setSubject("Contact - "+cont.getElement(MontroseContact.BUSINESS_NAME));
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
new MessageArguments(message));
} catch (PIMException e) {
throw new Exception(e.getMessage());
}Thanks in advance.
03-20-2010 11:17 AM
Here is a snippet:
multiPart = new Multipart();
PDAPContactAttachmentPart vcard = new PDAPContactAttachmentPart(multiPart,contact);
multiPart.addBodyPart(vcard);
03-21-2010 09:14 AM
Hey, it works.
Thanks a lot.
09-21-2010 05:50 PM
09-21-2010 08:56 PM
There is a product called REXconnect that does this. It is on App World, or you can go to www.rexwireless.com
11-08-2012 02:24 AM
Hi RexDoug, I am tried to implement your above code in my app, it works well but when i am tested to open the attached vcard it is empty and click add to contacts from the sent folder no contacts are added. I am testing in my device Bold9900. Please help me to retify my mistake.
public void getVCard() {
Multipart multipart = new Multipart();
Logger.logEventInfo("Begin Multipart ");
ContactList contacts = null;
try {
contacts = (ContactList) PIM.getInstance().openPIMList(
PIM.CONTACT_LIST, PIM.READ_WRITE);
Contact contact = contacts.createContact();
Logger.logEventInfo("createContact");
if (contacts.isSupportedField(Contact.FORMATTED_NAME) )
contact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE,"Blackberry");
Logger.logEventInfo("Fromatted name Blackberry");
if (contacts.isSupportedField(Contact.TEL))
contact.addString(Contact.TEL, Contact.ATTR_WORK, ""+909412345);
PDAPContactAttachmentPart vcard = new PDAPContactAttachmentPart(multipart,contact);
vcard.setContent(contact);
String[] data_formats = PIM.getInstance().supportedSerialFormats(
PIM.CONTACT_LIST );
ByteArrayOutputStream os = new ByteArrayOutputStream();
PIM.getInstance().toSerialFormat( contact, os, "UTF-8", data_formats[ 0 ] );
Logger.logEventInfo("Multipart attachment");
//SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart, "text/x-vcard", "contact1.vcf", os.toByteArray());
multipart.addBodyPart(vcard);
Logger.logEventInfo("Multipart");
Store store = Session.getDefaultInstance().getStore();
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder = folders[0];
Message message = new Message(sentfolder);
message.setContent(multipart);
message.setSubject("Contact - 123");
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
new MessageArguments(message));
} catch (Exception e) {
Logger.logEventInfo("Exception"+e.toString());
}
}
In simulator, i tried to add to contacts, i got empty screen like above.
11-08-2012 05:38 AM
Sorry for inconvience, myself fixed the issue, by refering the ContactLinkingDemo sample.
String[] name = new String[7];
if (contacts.isSupportedArrayElement(Contact.NAME, Contact.NAME_FAMILY)){
name[Contact.NAME_FAMILY] = FName;
Logger.logEventInfo("name "+ name[Contact.NAME_FAMILY].toString());
}
if (contacts.isSupportedArrayElement(Contact.NAME, Contact.NAME_GIVEN)){
name[Contact.NAME_GIVEN] = LName;
contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, name);
Logger.logEventInfo("contacts3 "+ name[Contact.NAME_GIVEN].toString());
}
contact.addString(Contact.TEL, Contact.ATTR_MOBILE, MobileNo);
Logger.logEventInfo("MobileNo "+ MobileNo);
Multipart multipart = new Multipart();
String[] data_formats = PIM.getInstance().supportedSerialFormats(
PIM.CONTACT_LIST );
ByteArrayOutputStream os = new ByteArrayOutputStream();
PIM.getInstance().toSerialFormat( contact, os, "UTF-8", data_formats[ 0 ] );
Logger.logEventInfo("Multipart attachment");
SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart, "text/x-vcard", "contact1.vcf", os.toByteArray());
multipart.addBodyPart(attach);
Thank you Rex.