function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deep SmithDeep Smith 

Email-to-Case to recognize IP and associate with a Country from their use sending email.

Is it possible for the Email-to-Case functionality to recognise the Country of the originating Email by IP Address?

When Email-to-Case creates a Case, we would like to automatically update the Country (custom picklist) field on case object based on IP address. or if any other way to do it I please let me know.

Any thoughts would be greatly appreciated.
 

Thanks!

PradeepgorePradeepgore
Hi Deep Smith

An idea was created earlier to add more fields to the Email to case functionality (https://ideas.salesforce.com/s/idea/a0B8W00000GdlopUAB/more-emailtocase-settings-for-case-fields).

Beacuse the email will contain only headers from the email service provider there is no way we can extract location or country information from it.

However, I can suggest a workaround that I have tested it in my personal org which is as below:
1. Enable email to case auto responses 
2. Create and associate a email template to auto response
Email will contain questions asking about details such as country, etc
3. After email is again sent back , it is attached to the same case
4. Extract all the information required and store it in custom fields.

Let me know the concerns in this approach if any. We can discuss further on pradeepgore60@gmail.com. If you honestly feel the time invested in reseraching and the approach found out works for you, please do not ignore it without mentioning it as the best answer.

Thanks,
Pradeep
Shri RajShri Raj
public class IpToCountry {
    public static String getCountry(String ip) {
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.ipdata.co/'+ip+'?api-key=test');
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        if (response.getStatusCode() == 200) {
            Map<String, Object> json = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            return (String) json.get('country_name');
        } else {
            return 'Error';
        }
    }
}