how to Detect Marketing and Role based emails programmatically? - spring-boot

I have requirements where I would have to distinguish emails whether it is regular email, Marketing email, or Role based email.
Marketing Emails: Emails that correspond to a marketing campaign. Typically sent to a batch of users and composed with tools like
MailChimp, etc...
Role-Based Emails: Emails addresses that are not associated with a particular person, but rather with a company, department, position, or
group of recipients (ex: noreply#, marketing#, support#, etc).
Can I identify this by email header information? Or is there any other way to achieve this?
Technology using:
Gmail API: to get email information
Spring boot: to process emails

By using the Gmail API you can retrieve the emails by using the following request:
GET https://gmail.googleapis.com/gmail/v1/users/{userId}/messages/{id}
Which will end up returning the body of a Message with the following similar structure:
{
"id": ID,
"threadId": THREAD_ID,
"labelIds": [
"CATEGORY_PROMOTIONS",
"UNREAD",
"INBOX"
],
"payload": {
"headers": [{
"name": "Reply-To",
"value": "NAME \u003cnewsletter#email.com\u003e"
},
{
"name": "Subject",
"value": "Week 9 Newsletter"
},
{
"name": "From",
"value": "NAME \u003csupport#email.com\u003e"
},
"body": {
"size": SIZE,
"data": ""
}
},
}
So depending on how you want to process these afterwards, you can use some of the following fields from the returned email:
labelIds - this field will contain all the labels attached to the incoming email which means that (depending on the settings you have for your inbox) you can easily check this email for instance as being a promotional email because of the CATEGORY_PROMOTIONS label attached to it;
Reply-To header - you can retrieve the email address here and later analyze it;
Subject header - assuming you have a list of keywords set up, you can search the subject of the email and later mark it based on the results;
From header - you can retrieve this email address here and again, based on a list of keywords, you can decided of which type this email is.
Reference
Gmail API Message Resource.

Related

Outlook REST API - Send As

I am currently using the Outlook REST API to send email. This is working fine when sending from a user mailbox such as:
https://outlook.office.com/api/v2.0/users/user#domain.com/sendMail
'user#domain.com' is the UPN of a valid user account in Azure AD.
What I need to do is 'send as' a shared mailbox. According to the documentation this can be achieved by changing the 'From' property in the JSON request body. An example would be:
{
"Message": {
"Subject": "Email Unit Test",
"Body": {
"ContentType": "HTML",
"Content": "Message body"
},
"ToRecipients": [
{
"EmailAddress": {
"Address": "recipient#somehost.com"
}
}
],
"Attachments": [
],
"From": {
"EmailAddress": {
"Address": "shared_mailbox#domain.com"
}
},
"Sender": {
"EmailAddress": {
"Address": "user#domain.com"
}
}
},
"SaveToSentItems": "false"
}
Now, when I give user#domain.com 'Send As' and 'Send On Behalf Of' access to the shared mailbox this works. The recipient gets an email with the from field saying 'user#domain.com On Behalf Of shared_mailbox#domain.com'. What I want however is for the email to appear as being sent from shared_mailbox only without the on behalf of user. To test this out further I removed the 'Send On Behalf Of' access and left 'Send As' access only. In the API I now get an error:
{
"error": {
"code": "ErrorSendAsDenied",
"message": "The user account which was used to submit this request does not have the right to send mail on behalf of the specified sending account., Cannot submit message."
}
}
Interestingly though, in my Outlook client I can still send an email from the shared mailbox and it works as expected with no 'on behalf of' in the From field. I'm starting to wonder whether this is a limitation of the REST API however there is nothing in the Microsoft docs to suggest this.
Has anyone had similar experiences with the REST API?
I tried to do the same thing and it seems the REST API allows you to implement "send on behalf of" but not "send as" feature.

How to fetch user's email address associated with Apple Pay Account from Apple Pay using JavaScript

I wanted to know if Apple has an API which we can use to fetch user's email address associated with apple pay account.
FYI I am using apple pay js (ApplePaySession) for apple pay.
Or is there another way to fetch user's email address from Apple pay in JavaScript.
Thank You!
The email address is provided within the onpaymentauthorized callback of your ApplePaySession.
Note: It is an inherited property, so it may be somewhat difficult to find in your developer console (in Chrome you've got to drill down into the event's __proto__ property).
You must specifically ask for the email address by including a requiredShippingContactFields property in your payment request:
requiredShippingContactFields: [
'phone',
'email'
]
And the email address will be available like so:
var session = new ApplePaySession(2, myPaymentRequest);
session.onpaymentauthorized = function(event){
console.log(event.payment.shippingContact.shippingAddress);
};
Once the user authorizes the transaction, you will get the shippingContact Object like this:-
{
"locality": “India",
"country": "India",
"postalCode": "95014-2083",
"administrativeArea": "CA",
"emailAddress": “sachin#example.com”,
"familyName": “Tendulkar",
"addressLines": [
"1 Infinite Loop"
],
"givenName": “Sachin",
"countryCode": "INDIA",
"phoneNumber": "(408) 555-5555"
}
from this object you can access the email id.

Is botId that bot scoped? Is it permanent?

Is the botId that I receive in the webhook only bot scope or is it unique across all the bots found?
Is it permanent or can it be changed?
By botId I mean the id in recipient.id and replyToId that you fill in send message request to endpoint https://smba.trafficmanager.net/apis/v3/conversations/{{skype.idRecipient}}/activities:
{
"text": "God help us!",
"type": "message",
"from": {
"id": "{{skype.idBot}}",
"name": "bot"
},
"recipient": {
"id": "{{skype.idRecipient}}",
"name": "user"
},
"replyToId": "{{skype.idBot}}"
}
The ID you are talking about is unique only in the current channel (Skype/Facebook/Slack...) as it is the ID of ChannelAccount.
Here are some statements from documentation:
Every bot and user has an account within each channel. The account
contains an identifier (id) and other informative bot non-structural
data, like an optional name.
Also
Channel accounts have meaning only within their associated channel
So it's not excluded that id may be repeated on another channels.
And what about permanency, it depends on the channel you use as stated in documentation again:
The stability of associations between IDs, accounts, mailboxes, and
people depends on the channel
But if you want it to be "unique across all the bots found" then you can create an id by combining AppID, ChannelID and User ID.
Also here is a quite informative guide about IDs in Bot Framework which may be helpful to you

How to uniquely identity a Person resource in Google People API response from a particular user?

Google People API, unlike Google Plus API doesn't provide an unique id for each Person resource in the response.
Why has this been deprecated/removed and how to uniquely identify a Person in an user's contacts list without an id?
In short, use resourceName as an ID.
The Google People API is the user's list of contacts and have IDs specific to the user. They can create contacts that only have a mailing address or only have a name and no contact info. There is no way for Google to logically collate all of these contacts across all of the Google Contacts users.
Specific contacts or a user have a resourceName field that uniquely identifies that resource (contact) for the authenticating user. You basically want to use that as an id. This is the value you for use, for example, to query People.get.
This is part of an example response of a single contact from People.connections:
{
"resourceName": "people/103710953423417258027",
"etag": "qwApd98gduQ=",
"metadata": {
"sources": [{
"type": "CONTACT",
"id": "1",
"etag": "#rj+KMFHVyHY="
}, {
"type": "PROFILE",
"id": "103710953423417258027",
"etag": "#4eZfef/IuMFw="
}],
"objectType": "PERSON"
},
...
}
resourceName is essentially the "id" of that contact and then in the metadata field it lists the sources the contact data comes from. E.g. CONTACT is for a Google Contacts entry where the user has manually entered name/phone/email/etc. PROFILE is a Google Profile, commonly with Google+ data.
The Person resource docs are a great place to learn more about these values.

Finding cleaned/bounced email addresses for a MailChimp campaign or list

I'd like to automate the gathering of unsubscribe and cleaned email accounts for a given campaign.
In the API playground, I see all the methods available on the List entity.
Unsubscribes
I see that it's in the LIST API
GET reports/xxxxxx/unsubscribed
Cleaned
Where can I find the cleaned/bounced emails from a list or campaign? I know I can see the count of bounced in various places, but I'd like to find the email addresses that actually bounced, and the first and last names of the list member. Basically I'd like the API same as the 'export cleaned to csv' available on the website.
How can I use the MailChimp 3.0 API to do this?
You can do
GET lists/list_id/members?status=unsubscribed
to get unsubscribed users
GET lists/list_id/members?status=cleaned
to get cleaned/bounced users
For the bounced emails in a specific campaign you need to do this:
GET /3.0/reports/campaign_id/email-activity
and iterate though all recipients in the campaign, manually locating actions with type=bounce.
{
"email_address": "xxx#example.com",
"activity": [
{
"action": "bounce",
"type": "hard",
"timestamp": "2019-04-08T00:00:00+00:00"
}
]
},
Unfortunately MailChimp has very bad performance on this endpoint, approximately 25 seconds to return activity for a campaign with 500 recipients.
Since soft bounce will not change status inside the list(audience), to get soft bounce email from the list without specific campaign, you can use
GET lists/{list-id}/members/{subscriber_hash}/activity
This endpoint will only return for single email(contact), so you need to iterate through all email(contact) in the list.
Sample response:
"activity": [
{
"action": "bounce",
"timestamp": "2019-05-01T23:02:26+00:00",
"type": "soft",
"campaign_id": "xxxxxxxxxx",
"title": "Xxxx Xxxxxxx"
},
{
"action": "sent",
"timestamp": "2019-05-01T23:00:00+00:00",
"type": "regular",
"campaign_id": "xxxxxxxxxx",
"title": "Xxxx Xxxxxxx"
}
],

Resources