[SalesForce] Email Service Verification

Will I need to verify my email in order to activate my email service?

I can't imagine that Gmail would allow an external domain to collect emails without permission…Yet salesforce hasn't sent me any type of forwarding verification request…

Furthermore, how can I monitor that my service is working?

Best Answer

Add a system.debug in your apex class for the subject and search for the text receiving mail from gmail in your debug log:

Here is a sample code below how I got the confirmation code

Enable the bounce back option to your mail so that you can track it easily.

Apex class:

global class EmailDemoReceive implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, 
                                                     Messaging.Inboundenvelope envelope) {
Account account;
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
System.debug('############'+result);

try {
// Look for account whose name is the subject and create it if necessary
if ([select count() from Account where Name = :email.subject] == 0) {
 account = new Account();
 account.Name = email.subject;
 System.debug('############'+account.Name );
 insert account;
} else {
account = [select Id from Account where Name = :email.subject];
}
// Convert cc'd addresses to contacts
for (String address : email.ccAddresses) {
 Contact contact = new Contact();
 Matcher matcher = Pattern.compile('<.+>').matcher(address);

// Parse addresses to names and emails
if (matcher.find()) {
String[] nameParts = address.split('[ ]*<.+>')[0].replace('"', '').split('[ ]+');

contact.FirstName = nameParts.size() > 1 ? nameParts[0] : '';
contact.LastName = nameParts.size() > 1 ? nameParts[nameParts.size()-1] : nameParts[0];
contact.Email = matcher.group().replaceAll('[<>]', '');
 } else {
contact.LastName = address;
contact.Email = address;
}

// Add if new
if ([select count() from Contact where Email = :contact.Email] == 0) {
 contact.AccountId = account.Id;
 insert contact;
 }
 }
// Save attachments, if any
for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
Attachment attachment = new Attachment();

attachment.Name = tAttachment.fileName;
attachment.Body = Blob.valueOf(tAttachment.body);
 attachment.ParentId = account.Id;
insert attachment;
 }
for (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
 Attachment attachment = new Attachment();

 attachment.Name = bAttachment.fileName;
 attachment.Body = bAttachment.body;
 attachment.ParentId = account.Id;
 insert attachment;
  }
  // Turn email body into note
  Note note = new Note();

  note.Title = email.fromName + ' (' + DateTime.now() + ')';
  note.Body = email.plainTextBody;
  note.ParentId = account.Id;
  insert note;
  result.success = true;
} catch (Exception e) {
  result.success = false;
  //result.message = "Oops, I failed";
}

return result;
 }
 }

Debug log:

[Account: (#220084905)  Forwarding Confirmation - Receive Mail from test@test.com 0017A000002OV3e]

220084905- Confirmation code