Working with HTML files in iOS Dev (Swift + Xcode) - ios

I have an HTML file (a template file for sending email). I'm using SendGrid to email users the receipt once they purchase something. I need to add some information to the HTML template file (pass a string values such as address, price, date of purchase, etc) before passing it to the SendGrid object.
A solution that came to my mind was to simply pass the HTML string but this is a bad solution since a template HTML will contain some javascript and other things.
What's the best solution to this problem?

I'm quite sure the best solution for this is to notify a service -> have the service send the HTML Script/Email or whatever it is you've made.
Sending the parameters you need to your backend/api and have that send the email.

Related

How to programmatically parse emails on an Outlook server and execute a script/task

My intranet web application (written in C#/ASP.Net MVC) sends email notifications in certain situations. I would like to intercept replies to such emails and perform actions based on the content of such replies.
I have no preference for scripting language - it could be Powershell, Python, VBA, anything - as long as I can parse the subject and body of the email, I can then alter the database of my web application through this script and pick up changes with an automated task, but I really have no clue where to start. I would be really grateful if someone could point me in the right direction.
QUESTION
How can I intercept emails sent to the Outlook server and perform action based on the content of such emails?
It sounds like you need an inbound email parsing service. I've worked with the one from SendGrid and it will catch any replies to a specific email address, and then post the email contents to an action on a controller in your MVC app. This will give you access to the full email contents and you can process it as needed.
See Setting up Inbound Parse

Edit or forward an existing mail into Gmail Compose Window

I have a Chrome extension which adds new functionalities to the Gmail interface.
I'm trying to create email "templates" which have a default header, footer and signature (using html, images & css). I want to open these templates in order to edit and send them, just filling the actual content of the email.
I was wondering if there is any way to open these emails directly into the Gmail Compose Window or something like that. Maybe there is a parameter to do this using the URL, like: https://mail.google.com/mail/?view=cm&fs=1&id=xxxxxxx.
I've tried loading the template using the body parameter, but it seems that it doesn't support html.
Any ideas?
Finally, I've found a way to open a mail directly into the "Compose" Window, ready to be edited and sent. It's so simple that I can not believe it takes me 2 days to figure it out:
Just use the url:
https://mail.google.com/mail/u/[accountNumber]/?zx=#[tag]?compose=[MailID]
accountNumber is useful if you have two or more accounts at the same time
tag its the mail list that you want to see behind the compose window (ussually inbox).
MailId ... well, the Gmail Message ID.
For instance, https://mail.google.com/mail/u/0/?zx=#inbox?compose=14bbb0dae14fec1f will open the inbox of your first account with a Compose Window opened and pre-populated with the e-mail data.
There is already a feature called "canned Response" in current gmail compose window which is probably solving the same problem that you are trying to solve with your extension.
well I am not sure URL has html support or not but I think it should not support it to protect user from cross-site scripting attacks.
you can also consider Gmail rest API if you want to compose gmail message with your own custom template but using this you may have to do lots of things from scratch.

Ping/Post Form Handling with PHP?

I'm working with a company on lead delivery, and they sent me some info regarding a Ping Post form setup. I've built hundreds of HTML forms processed by PHP (ie. sending an email/etc), but never something that would Ping a url, then return a value. The value it returns is XML.
Here's the purpose of the process:
I send a lead (form data) using the form with a particular zip code
This company parses that info, decides if it wants to "buy" it
Returns XML saying "Approved" or "Denied"
If "approved", I then post the data, and if "denied", I can do whatever I want
What is a common PHP method for doing this? I can research the code and put something together, just need to know what structure or PHP methods would work?
Thanks in advance.
You should be looking into RESTful Web Services.
here's a few examples that might help you
http://markroland.com/blog/restful-php-api/
http://coreymaynard.com/blog/creating-a-restful-api-with-php/
I did not create these examples, just what I found on Google.
I used file_get_contents(url) to handle the posting. The url contains inputs from the HTML form added as a query string, and the response is in XML which gets handled with simplexml_load_file().
As far as I understand your question what you need is to make an HTTP POST request and parse the incoming XML data.
I would rather not use file_get_contents() on remote servers - there are some potential security issues and it was missing some features the last time I checked. I strongly recommend cURL for remote HTTP/HTTPS communication.
Depending on the API you are posting to you might be able to use the SOAPclient class, but from the look of the response you got all you need is XML parser or Simple XML.
Anyway if you just need to check if a certain keyword (like Approved or Denied) is present you can use a simple string matching like this
if(strpos($response,'<STATUS>APPROVED</STATUS')!==false){
//approved
}
...

Mandrill API - download email content

We are currently using Mandrill to send emails. We use mandrill quite a few different systems to send emails.
Is there any API way to get the content of a sent email? I Know mandrill stores a copy for up to 30 days.
At this time, there's not an API for the email contents. If you're using templates, you can use the templates/render API call to get the rendered HTML of a template with merge tags and the like, but it isn't the actual content of a sent email.
You can use the messages.content method, you just need the API key and the message ID (which is returned in the send call).
Bear in mind that Mandrill only saves the content for 24h by default, and it can be extended up to 30 days by paying. So make sure you make the messages.content call within that time frame.
Also, other people have had trouble when calling messages.content too soon, as it appears that the content takes a bit to be indexed (see answer in this post)

Accept and parse information from email

What I would like to accomplish is for a user to be able to send an email to a designated email address. Then once that email has been obtained, run a script that parses the body section of the email and carries out various tasks with the information provided in the email
(The data coming in from the email will be structured in an xml type format).
In my mind this seems like a simple task to accomplish but I'm not all that familiar with the inner workings of email. My questions are:
How will I know once an email has been obtained from the sender so that it can be processed?
How can I use php to obtain the text found in the email?
If you have PHP running on your mail server, then it's possible to pipe incoming mail to a PHP script. Then, your PHP script can parse the body of each incoming message as it arrives. See http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/ for more info.
I agree with the other responses, that piping to a php application should be your first option (if the mail server and php are the same)
Otherwise if you have an external mail server you will need to poll the email address at regular intervals and check for new emails.
Extracting plain text body from an email message is not too hard, but getting to attachments can be a pain sometimes.
You will need to use a cronjob to trigger your script at regular intervals
To fetch the email from the server and parse it, I have used the php IMAP functions
http://php.net/manual/en/book.imap.php
You can also use 3rd party services like MandrillApp which will receive the message, break it into parts, and call your application via a webhook.
http://help.mandrill.com/entries/21699367-Inbound-Email-Processing-Overview

Resources