You need to sign in to do that
Don't have an account?

how to auto populate contact records from inbound mail attachment
Hii All,
Actually i need to get attachment consisting of listof contact names,phone,mailingcity from inbound mail (i.e.,email services) and need to generate records from that attachment automatically. I have an apex class regarding getting attachment from inbound mail. But not able to retrieve records from attachment. Can anyone help in this?
Here is the code
global class ContactEmailservice implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
Contact contact = new Contact();
contact.FirstName = email.fromname.substring(0,email.fromname.indexOf(' '));
contact.LastName = email.fromname.substring(email.fromname.indexOf(' '));
contact.Email = envelope.fromAddress;
insert contact;
System.debug('====> Created contact '+contact.Id);
Attachment attachment = new Attachment();
attachment.ParentId = contact.Id;
attachment.Name = email.subject;
attachment.Body = Blob.valueOf(email.HtmlBody);
insert attachment;
return result;
}
}
Actually i need to get attachment consisting of listof contact names,phone,mailingcity from inbound mail (i.e.,email services) and need to generate records from that attachment automatically. I have an apex class regarding getting attachment from inbound mail. But not able to retrieve records from attachment. Can anyone help in this?
Here is the code
global class ContactEmailservice implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
Contact contact = new Contact();
contact.FirstName = email.fromname.substring(0,email.fromname.indexOf(' '));
contact.LastName = email.fromname.substring(email.fromname.indexOf(' '));
contact.Email = envelope.fromAddress;
insert contact;
System.debug('====> Created contact '+contact.Id);
Attachment attachment = new Attachment();
attachment.ParentId = contact.Id;
attachment.Name = email.subject;
attachment.Body = Blob.valueOf(email.HtmlBody);
insert attachment;
return result;
}
}
As you got the attachment and its body, now you can traverse the content of body. You can split each line of code with '\n' and as per content you can perform your action.
Regards
Mohit Bansal
In case, you face any issue, drop me message on forum or Skype me @mohit_bansal17, if you need any help.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.