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

Parsing an email subject from a separate portal
I have a requirement for parsing an email subject which is sent from a different portal .
Can anybody plz help me to resolve this.
Any help appreciated.
As its possible to parse inbound emails by using Email Servcies. Where you have to write a class extending inbound messaging class and create a Email service to use that class. So that email service gives you an address to get emails / parse emails .. YOu can do this way.
All Answers
As its possible to parse inbound emails by using Email Servcies. Where you have to write a class extending inbound messaging class and create a Email service to use that class. So that email service gives you an address to get emails / parse emails .. YOu can do this way.
Thanks..
I created a class which implements Messaging.InboundEmailHandler and created an email service where in accept email from is gmail.com .
But when i am trying to send an email to add a contact, its not working. Does it requires any integration with gmail.
I got it...
Thanks.
start with a very small scenario. Hope this will help you.
Create an object Profile with Below fields Highlighted in Red.
Lets say this is the Sample email template you are receving
Department Name: Salesforce Department
Employee Name: Test Name
Salary: 30000
mail Id: test@gmail.com
Create Apex class
//Create a class
global class myDepartment implements Messaging.InboundEmailHandler {
//ok
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) { //ok
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
String subject = email.subject;
string mailBody = '';
mailBody = email.plainTextBody;
system.debug('mailBody ' +mailBody);
string departmentName;
string employeeName;
string salary;
string emailId;
string[] stringTest = mailBody.split('\n');
system.debug('mailbody record length ' + stringTest.size());
system.debug('first line ' + stringTest[0]);
string[] Name = stringTest[0].split(': ');
departmentName = Name[1];
Name = stringTest[1].split(': ');
employeeName = Name[1];
Name = stringTest[2].split(': ');
salary = Name[1];
Name = stringTest[3].split(': ');
emailId = Name[1];
system.debug('dpetNAme : ' + departmentName + ' empName ' + employeeName + ' salary ' + salary + ' meialid ' + emailId);
department__c dept = new department__c();
dept.Name = departmentName;
dept.employee_name__c = employeeName;
dept.mail_id__c= emailId;
dept.salary__c= decimal.valueOf(salary);
insert dept;
Messaging.InboundEmail.TextAttachment[] tAttachments = email.textAttachments;//text attachements --ok
Messaging.InboundEmail.BinaryAttachment[] bAttachments = email.BinaryAttachments;//binary attach--ok
String contents=''; //ok
//getting the csv file
if(bAttachments !=null){ //ok
for(Messaging.InboundEmail.BinaryAttachment bAttach : bAttachments){ //ok
if(bAttach.filename.endsWith('.txt')){ //ok
contents = bAttach.body.toString(); //ok
}
}
}
else if(tAttachments !=null)
{
for(Messaging.InboundEmail.TextAttachment tAttach : tAttachments){ //ok
if(tAttach.filename.endsWith('.txt'))
{ //ok
contents = tAttach.body; //ok
}
}
}
Attachment attach = new Attachment();
attach.Body = Blob.valueOf(contents);
attach.Name = String.valueOf('xyz.txt');
attach.parentId = dept.Id;
insert attach;
return Result;
}
} //ok
Now create an email Services. Setup--> Develop--> Email Services
-->New Email Services
-->Apex class --> myDepartment-->save..
New email Address...
Now send the above template from ur mail... Make sure you enable Debug logs.. So you can track..
If this solution helps you Please Tag as solution.