• guneetsahai
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies
Hi,

I'm using Email Service which is accepting incoming emails from clients.

Lately I have noticed a rather peculiar behavior. Basically any email that has text portion greater than 100k in size is bounced by the system. The handler associated with the email service is not invoked for such emails. Somehow this has started happening recently {I managed to find emails in my system that had size greater than 100k and were delivered fine to my handler}. I tried searching forums and documentation but couldn't find any help there. The bounced email contains the following message

This message was created automatically by the mail system (ecelerity).

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

>>> xxxxxxinboundemail@o-2ggm9ec90dyv38pu6lxlxg0o3.in.salesforce.com
>>> (reading confirmation): 554 Text body part exceeds max size of
>>> 100000



My application relies heavily on email (customers are sending emails which are copied into sf) and emails not reaching SF is very serious for me. Is this limit of 100k customizable? Can I change this behavior of "bouncing" to something else {deliver truncated email perhaps or something else}, If no, can I at-least get a notification in some form in my app about a missed email.

Will appreciate any help.


Thanks
Guneet Sahai
http://guneetsahai.blogspot.com
Hi,
 
My name is Guneet and I'm working on building an application for a client over Force.com.
 
One of the important function of the application is to receive in-coming email, parse it and insert/update custom objects in salesforce. For this purpose, I have created an email service which is delivering mails to my Email Handler. It mostly seems to be working fine, but I noticed that on and off some emails do not get processed.
 
While investigating the problem, I wrote a simple java test application (code at the end of this post) that could send emails in a loop. I reduced the Email Handler in my sandbox environment to a single Debug Statement (as that shown below). To my surprise, I noticed that with as little as 10 emails being sent in a loop (from a single thread) 6-8 emails really make it to my handler. Not sure what happens to the remaining ones. I'm sure this is not a problem in my email server or my test application - coz when I add another email address in cc or to field, that email address gets all 10 emails. Can anybody explain this behavior to me. This is really important for the application not to miss any email.
 
The email service was created with default options - "Over Email Rate Limit Action" set to "bounce", I later tried setting it to re-queue but nothing really changed. Still a few emails were getting eaten up.
 
 
==== Email Handler ====

/**

* Test Email Handler

*

* This email handler is just meant to print a line

* with the subject of incoming email.

*

* @author - Prashant

* @date - 2nd June 2008

*/

global class CountEmailHandler implements Messaging.InboundEmailHandler

{

global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail TestEmail, Messaging.InboundEnvelope envelope)

{

System.debug ('Subject ' + TestEmail.subject);

Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

return result;

}

}

 

 

 

======== Java program used for testing ========

 

 

String from = "salesforce@xxxx.com"; // xxxx was replaced with the actual domain

String[] to = {"prastestservice@x-4eywdo2vlejms9tj4t1t9ef64.in.sandbox.salesforce.com"};

Properties properties = new Properties ();
properties.put("mail.transport.protocol",   "smtp");
properties.put("mail.smtp.starttls.enable", "false");
properties.put("mail.smtp.host",     "mail.xxxx.com");
properties.put("mail.smtp.auth",     "true");
properties.put("mail.smtp.user",     "abcd@xxxx.com");
properties.put("mail.smtp.password",    "password");

 

for (int i=0; i<10; ++i)
  MailUtils.sendEmail2 (properties, from, to, null, null, "Test Email - " + id, "This is just a test", "text/html", null);

 

 

 

 

=========== MailUtils.sendEmail2 ==================


 

 

 

 

 

 

 

 /**
  * Sends an email with attachment
  *
  * @param properties
  * @param from
  * @param to
  * @param cc
  * @param subject
  * @param content
  * @param contentType
  * @param attachments
  * @throws NucleoException
  */
 public static void sendEmail2 (Properties properties , String from, String[] to, String[] cc, String[] bcc, String subject, String content, String contentType, List<FileItem> attachments)
  throws NucleoException
 {
    if (to == null || to.length == 0)
         throw new NucleoException ("Recipient Address Can't be null or empty");


    try
    {
         // create a new session
         Session session = Session.getInstance(properties, new SMTPAuthenticator(properties));

 

 


         // construct the message
         MimeMessage mimemessage = new MimeMessage(session);
         mimemessage.setFrom(new InternetAddress(from));
         mimemessage.setSubject(subject);
         mimemessage.setSentDate(new Date ());  // Fix for issue id = 83
         _addAddressesToEmail (mimemessage, to, cc, bcc);
         // mimemessage.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("isangoinboundemail@o-2ggm9ec90dyv38pu6lxlxg0o3.in.salesforce.com"));
         // mimemessage.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("test_email_service@4alc8hbts0iciftowkajep7mu.in.salesforce.com"));

 


         // Create an empty multi Part object
         MimeMultipart mimemultipart = new MimeMultipart();

 

 

         // Add body to multi part
         MimeBodyPart mimebodypart  = new MimeBodyPart();
         mimebodypart.setContent(content, contentType);
         mimemultipart.addBodyPart(mimebodypart);

 

 

         // set attachments
         if(attachments != null && attachments.size() > 0)
         {

.......

         }

 


         // set multi part to message
         mimemessage.setContent(mimemultipart);

 


         // send message
         Transport.send(mimemessage);
    }
    catch(Exception exception)
    {

......
    }
 }

Hi,

My name is Guneet and I'm developing an application for my company over force.com. My questions are

a) I suspect that the method handleInboundEmail ( ) in InboundEmailHandler is not thread safe. Is this correct? I tried searching the documentation for any information on this but couldn't find anything on it.

b) If this is true and synchronization is not done by the force.com platform, how can I acheive this in my code? I tried searching for ways to protect code against for multiple threads but couldn't find a way to do that.

Here's what I did  - My application has a custom Object called "Travel Booking" (api name = booking__c  : see code snippet at the end of this post) which has one custom field called "Ref No". This application also has an Email Handler, which on getting an email checks if Ref No is found in the email subject, if yes then further checks if a Travel Booking exists in SF with same "Ref No" in SF database.

o If it exists, then links the incoming email with the Travel Booking instance

o If not, creates a new custom object instance with the Ref No.

With this code, I was hoping that there would never be situations when there are more than one Travel Booking with same Ref No. This is more or less working fine. However I have noticed that, if I send multiple emails almost at the same time then the system ends up creating multiple booking objects all with the same ref no. My guess is that these simultaneous emails are getting processed at the same time and therefore the check "to see if Travel Booking with incoming Ref No exists" fails for all these emails and all end up creating a new instance of Booking Object.

Code Snippet of my email handler can be found below.

Thanks
Guneet Sahai




============== My Email Handler =============

global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope)
{
        ......
        ......
        .......

        // check if subject contains ISAXXXX 
        if (email.subject.contains ('ISA'))
        {
                String subject = email.subject;
                integer startIndex = subject.indexOf ('ISA') - 1;
                integer endIndex = startIndex + 8;
                if (endIndex > subject.length ())
                endIndex = endIndex - 1;



                if (startIndex > -1 && endIndex > -1)
                {
                        // get the 4 digit booking no from subject - ISAXXXX
                        String bookingRefNo = email.subject.substring (startIndex + 1, endIndex);
                        System.debug ('Booking Ref No found in subject of email (' + bookingRefNo + ')');


                        // fetch booking details for booking ref no
                        Booking__c[] bookings = [Select b.Id, b.Status__c, b.name, b.owner__c,b.co_owner__c from Booking__c b where Ref_No__c like :bookingRefNo limit 1];


                        // if not empty get the booking id
                        if (!bookings.isEmpty ())
                        {
                                .....
                                .....
                                .....
                        }
                        else if (bookings.isEmpty ())
                        {
                                Booking__c newBok = new Booking__c ();
                                newBok.Status__c = 'New';
                                newBok.Ref_No__c = bookingRefNo; 
                                insert newBok;


                                owningBookingId = newBok.id;
                                System.debug ('Inserted Booking ' + newBok.id + ' Name = ' + newBok.name);
                        }
                }
        }
        else
                System.debug ('Booking Ref No NOT found in incoming email'); } 

        ...........

}

I have a custom object which might have HTML data in one of its field (of type text area). Is there a way by which I can enable showing the content in Rich text (instead of showing the code with HTML tags in it).

I did some searching around this topic and I understand this is possible with VisualForce but I don't think visualforce is available in enterprise edition (and hence not usable for me). Another option might be to write an S-Control which might be able to do the job, but I'm hoping that there is some HTML Enabled Text Area (Field Type) which simplifies this job even more, but couldn't really find it in my search.

Thanks for helping me out.
Guneet Sahai
http://www.guneetsahai.com



Hi,

I need to add a user-specified attachment to an outbound email that gets generated when the user clicks a button.

Though I'm fairly new to SF platform, but have gone through the documentation to some extent & am able to send a regular email without attachments. I have seen a Java Sample here that gives an example on how to attach a dummy byte [ ] to an outgoing email. However I'm not sure if I understand how to do this for attaching a file specified by the user at runtime.

Possible approaches that come to my mind are

a) Have Email Service running on a separate server (a J2EE app perhaps) which exposes the page through which the user sends an email. On Clicking the "Send" button on this page, the browser first uploads the attachment to the server and the app then sends the email using standard Java Mail APIs.  
        [I don't quite like this approach since I'm moving away from on-demand nature of the app ]

b) Set up a File server on which the browser uploads the attachments, then inserts a new Document/Attachment (with the right URL) into SF. It then invokes an apex function that takes the document IDs and sends an email with required attachments.
        [Though better than option a), but it still requires me to maintain a file server]


My questions

i) Is there a better way of doing this?
ii) Is there an in-built feature somewhere in SF that simplifies this task?


Thanks in advance
Guneet Sahai
Freelance Developer
http://www.guneetsahai.com

         



Hi,

I'm using Email Service which is accepting incoming emails from clients.

Lately I have noticed a rather peculiar behavior. Basically any email that has text portion greater than 100k in size is bounced by the system. The handler associated with the email service is not invoked for such emails. Somehow this has started happening recently {I managed to find emails in my system that had size greater than 100k and were delivered fine to my handler}. I tried searching forums and documentation but couldn't find any help there. The bounced email contains the following message

This message was created automatically by the mail system (ecelerity).

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

>>> xxxxxxinboundemail@o-2ggm9ec90dyv38pu6lxlxg0o3.in.salesforce.com
>>> (reading confirmation): 554 Text body part exceeds max size of
>>> 100000



My application relies heavily on email (customers are sending emails which are copied into sf) and emails not reaching SF is very serious for me. Is this limit of 100k customizable? Can I change this behavior of "bouncing" to something else {deliver truncated email perhaps or something else}, If no, can I at-least get a notification in some form in my app about a missed email.

Will appreciate any help.


Thanks
Guneet Sahai
http://guneetsahai.blogspot.com
Hi All,
 
   I was able to create cases for contact from the information from an email send using apex
email services.I have created an apex class and associated an email service for the same.
I have a requirement to save attachments contained in those emails to a local folder in
system and provide a reference to the same while creating the case from email?
Anybode has the apex class code for the same.
 
 
Thanks and Regards
Raji
Hi,
 
My name is Guneet and I'm working on building an application for a client over Force.com.
 
One of the important function of the application is to receive in-coming email, parse it and insert/update custom objects in salesforce. For this purpose, I have created an email service which is delivering mails to my Email Handler. It mostly seems to be working fine, but I noticed that on and off some emails do not get processed.
 
While investigating the problem, I wrote a simple java test application (code at the end of this post) that could send emails in a loop. I reduced the Email Handler in my sandbox environment to a single Debug Statement (as that shown below). To my surprise, I noticed that with as little as 10 emails being sent in a loop (from a single thread) 6-8 emails really make it to my handler. Not sure what happens to the remaining ones. I'm sure this is not a problem in my email server or my test application - coz when I add another email address in cc or to field, that email address gets all 10 emails. Can anybody explain this behavior to me. This is really important for the application not to miss any email.
 
The email service was created with default options - "Over Email Rate Limit Action" set to "bounce", I later tried setting it to re-queue but nothing really changed. Still a few emails were getting eaten up.
 
 
==== Email Handler ====

/**

* Test Email Handler

*

* This email handler is just meant to print a line

* with the subject of incoming email.

*

* @author - Prashant

* @date - 2nd June 2008

*/

global class CountEmailHandler implements Messaging.InboundEmailHandler

{

global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail TestEmail, Messaging.InboundEnvelope envelope)

{

System.debug ('Subject ' + TestEmail.subject);

Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

return result;

}

}

 

 

 

======== Java program used for testing ========

 

 

String from = "salesforce@xxxx.com"; // xxxx was replaced with the actual domain

String[] to = {"prastestservice@x-4eywdo2vlejms9tj4t1t9ef64.in.sandbox.salesforce.com"};

Properties properties = new Properties ();
properties.put("mail.transport.protocol",   "smtp");
properties.put("mail.smtp.starttls.enable", "false");
properties.put("mail.smtp.host",     "mail.xxxx.com");
properties.put("mail.smtp.auth",     "true");
properties.put("mail.smtp.user",     "abcd@xxxx.com");
properties.put("mail.smtp.password",    "password");

 

for (int i=0; i<10; ++i)
  MailUtils.sendEmail2 (properties, from, to, null, null, "Test Email - " + id, "This is just a test", "text/html", null);

 

 

 

 

=========== MailUtils.sendEmail2 ==================


 

 

 

 

 

 

 

 /**
  * Sends an email with attachment
  *
  * @param properties
  * @param from
  * @param to
  * @param cc
  * @param subject
  * @param content
  * @param contentType
  * @param attachments
  * @throws NucleoException
  */
 public static void sendEmail2 (Properties properties , String from, String[] to, String[] cc, String[] bcc, String subject, String content, String contentType, List<FileItem> attachments)
  throws NucleoException
 {
    if (to == null || to.length == 0)
         throw new NucleoException ("Recipient Address Can't be null or empty");


    try
    {
         // create a new session
         Session session = Session.getInstance(properties, new SMTPAuthenticator(properties));

 

 


         // construct the message
         MimeMessage mimemessage = new MimeMessage(session);
         mimemessage.setFrom(new InternetAddress(from));
         mimemessage.setSubject(subject);
         mimemessage.setSentDate(new Date ());  // Fix for issue id = 83
         _addAddressesToEmail (mimemessage, to, cc, bcc);
         // mimemessage.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("isangoinboundemail@o-2ggm9ec90dyv38pu6lxlxg0o3.in.salesforce.com"));
         // mimemessage.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("test_email_service@4alc8hbts0iciftowkajep7mu.in.salesforce.com"));

 


         // Create an empty multi Part object
         MimeMultipart mimemultipart = new MimeMultipart();

 

 

         // Add body to multi part
         MimeBodyPart mimebodypart  = new MimeBodyPart();
         mimebodypart.setContent(content, contentType);
         mimemultipart.addBodyPart(mimebodypart);

 

 

         // set attachments
         if(attachments != null && attachments.size() > 0)
         {

.......

         }

 


         // set multi part to message
         mimemessage.setContent(mimemultipart);

 


         // send message
         Transport.send(mimemessage);
    }
    catch(Exception exception)
    {

......
    }
 }

Hi,

My name is Guneet and I'm developing an application for my company over force.com. My questions are

a) I suspect that the method handleInboundEmail ( ) in InboundEmailHandler is not thread safe. Is this correct? I tried searching the documentation for any information on this but couldn't find anything on it.

b) If this is true and synchronization is not done by the force.com platform, how can I acheive this in my code? I tried searching for ways to protect code against for multiple threads but couldn't find a way to do that.

Here's what I did  - My application has a custom Object called "Travel Booking" (api name = booking__c  : see code snippet at the end of this post) which has one custom field called "Ref No". This application also has an Email Handler, which on getting an email checks if Ref No is found in the email subject, if yes then further checks if a Travel Booking exists in SF with same "Ref No" in SF database.

o If it exists, then links the incoming email with the Travel Booking instance

o If not, creates a new custom object instance with the Ref No.

With this code, I was hoping that there would never be situations when there are more than one Travel Booking with same Ref No. This is more or less working fine. However I have noticed that, if I send multiple emails almost at the same time then the system ends up creating multiple booking objects all with the same ref no. My guess is that these simultaneous emails are getting processed at the same time and therefore the check "to see if Travel Booking with incoming Ref No exists" fails for all these emails and all end up creating a new instance of Booking Object.

Code Snippet of my email handler can be found below.

Thanks
Guneet Sahai




============== My Email Handler =============

global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope)
{
        ......
        ......
        .......

        // check if subject contains ISAXXXX 
        if (email.subject.contains ('ISA'))
        {
                String subject = email.subject;
                integer startIndex = subject.indexOf ('ISA') - 1;
                integer endIndex = startIndex + 8;
                if (endIndex > subject.length ())
                endIndex = endIndex - 1;



                if (startIndex > -1 && endIndex > -1)
                {
                        // get the 4 digit booking no from subject - ISAXXXX
                        String bookingRefNo = email.subject.substring (startIndex + 1, endIndex);
                        System.debug ('Booking Ref No found in subject of email (' + bookingRefNo + ')');


                        // fetch booking details for booking ref no
                        Booking__c[] bookings = [Select b.Id, b.Status__c, b.name, b.owner__c,b.co_owner__c from Booking__c b where Ref_No__c like :bookingRefNo limit 1];


                        // if not empty get the booking id
                        if (!bookings.isEmpty ())
                        {
                                .....
                                .....
                                .....
                        }
                        else if (bookings.isEmpty ())
                        {
                                Booking__c newBok = new Booking__c ();
                                newBok.Status__c = 'New';
                                newBok.Ref_No__c = bookingRefNo; 
                                insert newBok;


                                owningBookingId = newBok.id;
                                System.debug ('Inserted Booking ' + newBok.id + ' Name = ' + newBok.name);
                        }
                }
        }
        else
                System.debug ('Booking Ref No NOT found in incoming email'); } 

        ...........

}

I have a custom object which might have HTML data in one of its field (of type text area). Is there a way by which I can enable showing the content in Rich text (instead of showing the code with HTML tags in it).

I did some searching around this topic and I understand this is possible with VisualForce but I don't think visualforce is available in enterprise edition (and hence not usable for me). Another option might be to write an S-Control which might be able to do the job, but I'm hoping that there is some HTML Enabled Text Area (Field Type) which simplifies this job even more, but couldn't really find it in my search.

Thanks for helping me out.
Guneet Sahai
http://www.guneetsahai.com



Hi All,
 
I am creating a form through s-control. In this we need to upload pdf file from the client machine.
 
Please provide any sample code for uploading file through s-control
 
Thanks in Advance
 
Regards
Tom
  • February 25, 2008
  • Like
  • 0