I want to create an email/message throw Google API. user messages send
I managed to create a simple email (only text) using this endPoint
POST https://gmail.googleapis.com/gmail/v1/users/{userId}/messages/send
and inserting in the body only the "raw" field with the Base64 Encoded string that contains this info eg:
Now I'm trying to send an Email with some attachments and i can't get it to work.
I found only example with Java/Javascript libraries but I want to made it throw standard Rest Api Call (Now i'm using Postman to test this endpoints).
First of all , Have I to use https://developers.google.com/gmail/api/reference/rest/v1/users.messages/send
OR
POST https://gmail.googleapis.com/upload/gmail/v1/users/{userId}/messages/send
?
Can you leave an example of an email with a body text and two attachments (for example two pdf) ?
Thank you
If you are using postman, I suggest you to follow these steps to make it work:
1.) The endpoint to use is: https://gmail.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=multipart
2.) The content type header of the request should be: Content-Type: message/rfc822
3.) The body of the request should be: raw -> text
4.) The content of the body should have the following format:
Content-Type: multipart/mixed; boundary=foo_bar_baz
MIME-Version: 1.0
to: recipient#email.com
from: sender#email.com
subject: POSTMAN Rest API Execution
--foo_bar_baz
Content-Type: text/html; charset="UTF-8"
MIME-Version: 1.0
<h1>What is Lorem Ipsum?</h1>
<p style="color: darkred">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum<p>
--foo_bar_baz
Content-Type: application/pdf
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Attachment_file.pdf"
JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9UaXRsZSAoUHJvamVjdCBwcm9wb3NhbCkKL1Byb2R1Y2VyIChTa2lhL1BERiBtMTAzIEdvb2dsZSBEb2NzIFJlbmRlcmVyKT4+CmVuZG9iagozIDAgb2JqCjw8L2NhIDEKL0JNIC9Ob3JtYWw+PgplbmRvYmoKNyAwIG9iago8PC9UeXBlIC9YT2JqZWN0Ci9TdWJ0eXBlIC9JbWFnZQovV2lkdGggMTIwMAovSGVpZ2h0IDEyCi9Db2xvclNwYWNlIC9EZXZpY2VSR0IKL0JpdHNQZXJDb21wb25lbnQ==
--foo_bar_baz--
As a side note, I also followed the REST API documentation but I was getting all kind of error messages because I was confused. However, I found an old question that was able to help me to formulate the correct way of using the api... you might want to check it --> Mail attachment wrong media type Gmail API
If you have time, you might also want to read this --> https://www.rfc-editor.org/rfc/rfc2046. Reading it helped me overcome the confussion I was going through and gave me clarity as to why the above steps worked.
Related
My Odata service url : https://odataservices.azurewebsites.net/People
Response:
{"#odata.context":"https://odataservices.azurewebsites.net/$metadata#People","value":[{"ID":"001","Name":"Angel","Description":null},{"ID":"002","Name":"Clyde","Description":"Contrary to popular belief, Lorem Ipsum is not simply random text."},{"ID":"003","Name":"Kunal","Description":"It has roots in a piece of classical Latin literature from 45 BC, making Lorems over 2000 years old."},{"ID":"004","Name":"tejas","Description":"It has roots in a piece of classical Latin literature from 45 BC, making Lorems over 2000 years old."}]}
I would like to add "#odata.deltaLink" as a another property in the response which would contain links for the incremental changes.
How would i do that in ASP.NET Web API solution?
The user can obtain a delta link from each entity API in the library by including the odata.track-changes preference in the header of the request. The response to the GET request returns a deltaLink parameter, providing an opaque URL.
See more here: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-connect-apps-delta
I'm new to OneM2M Protocol.
Searching for the OneM2M TS0001 documents, I don't get any idea of determining the Notification MIME type.
How do I determine MIME type(e.g. 'application/json', 'application/xml') of notification?
I couldn't find anything in Subscription's attributes.
This is an example of application developer guide from the site below. How did they decide to send this notification as the type of 'application/xml'?
Post a notification to ADN-AE1
HTTP Request with XML payload
POST / HTTP/1.1
Host: 192.168.0.10:9090
X-M2M-Origin: /mn-cse
X-M2M-RI: notif-12345
Content-Type: application/xml
<?xml version="1.0" encoding="UTF-8"?>
<m2m:sgn xmlns:m2m="http://www.onem2m.org/xml/protocols" rn="cin-394798749">
<nev>
<rep>
<m2m:cin>
<ty>4</ty>
<ri>cin-394798749</ri>
<pi>cnt-790965889</pi>
<ct>20150925T050534</ct>
<lt>20150925T050534</lt>
<et>20151107T154802</et>
<st>0</st>
<cnf>text/plain:0</cnf>
<cs>3</cs>
<con>ON</con>
</m2m:cin>
</rep>
</nev>
<sur>/mn-cse/sub-856593979</sur>
</m2m:sgn>
http://www.onem2m.org/application-developer-guide/implementation/notifications
You should have a look at TS-0004 "Service Layer Core Protocol Specification", section 6.7 "oneM2M specific MIME media types". There you can find all the oneM2M specific MIME types.
According to that table, the correct MIME type for a notification and XML encoding is application/vnd.onem2m-ntfy+xml.
That said, you might also check TS-0009 "HTTP Protocol Binding", sections 6.4.2 "Accept" and 6.4.3 "Content-Type". Here, the specification says, for example for Content-Type:
Any HTTP request or response containing message-body shall include the Content-type header set to one of “application/xml”, “application/json”, or the oneM2M defined media types defined in clause 6.7 of oneM2M TS-0004.
Since one can determine unambiguously the type of the resource by looking at the element *m2m:sgn", setting *application/xml" as the Content-Type for XML encoded resources is usually enough.
You can download the latest versions of the oneM2M specifications at http://www.onem2m.org/technical/published-drafts
Update
The CSE determines the encoding type (xml, json or cbor) for the notification message by looking at the optional ty parameter of the notificationURI attribute.
This is specified in TS-0001, section 9.6.8 "Resource Type subscription". The subscriber of a notification can add a type parameter (e.g. ty=xml) to the notificationURI. If this is left out, then the CSE chooses a default encoding.
I have a question about net/smtp
For html emails you have to set this in the header of the email content-type: text/html . However, if you want to send an attachment you have to change it to content-type: multipart/mixed. Which would make the html email...not html anymore.
So the question is.. how do I accomplish both? HTML and attachment?
Thank you
Each attachment has its own MIME type
Each part of a multipart email has its own MIME type. So, while the email's content-type is "multipart/mixed", each attachment has its own MIME type (text, HTML, etc).
Here is an example multipart email from MIME and HTML in Email by Doug Steinwand:
To: whoever#someplace.com
Subject: MIME test
Content-type: multipart/mixed; boundary="theBoundaryString"
--theBoundaryString
Plain text message goes in this part. Notice that it
has a blank line before it starts, meaning that this
part has no additional headers.
--theBoundaryString
Content-Type: text/html
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Content-Base: "http://somewebsite.com/"
<body><font size=4>This</font> is a
<i>test</i>.
--theBoundaryString--
Here you can see that the text attachment has no explicit content type. When an attachment has no explicit content type, it is US ASCII TEXT. The HTML attachment has a content type of "text/html". There could be other attachments, each with their own MIME type.
Consider using the "mail" Gem
The mail gem makes sending and parsing multi-part emails very easy. It is stable, well maintained, and widely used.
This example from its README shows how to send a multi-part mail with a text part and an HTML part:
mail = Mail.deliver do
to 'nicolas#test.lindsaar.net.au'
from 'Mikel Lindsaar <mikel#test.lindsaar.net.au>'
subject 'First multipart email sent with Mail'
text_part do
body 'This is plain text'
end
html_part do
content_type 'text/html; charset=UTF-8'
body '<h1>This is HTML</h1>'
end
end
I'm trying to read an email using ruby mail gem.
But mail.body.decoded returns me not just the body message. How can I clean up this body message and remove unwanted text like:
-20cf30433c9a437cc304939017ef\nContent-Type: text/plain; charset=ISO-8859-1\nContent-
message = $stdin.read
mail = Mail.read_from_string(message)
puts mail.body.decoded
--20cf30433c9a437cc304939017ef\nContent-Type: text/plain; charset=ISO-8859-1\nContent-Transfer-Encoding: quoted-printable\n\n REAL BODY TEXT \\n\n--20cf30433c9a437cc304939017ef\nContent-Type: text/html; charset=ISO-8859-1\nContent-Transfer-Encoding: quoted-printable\n\n<br clear=3D\"all\">--20cf30433c9a437cc304939017ef--
How can I clean up this email body mail message extracting only the REAL BODY TEXT , without ANY header ?
I'm creating a simple Ticket System based in Ruby on Rails, and a ticket is created when an email is received by ticket#mydomain.com. But when the message is in HTML format the BODY TEXT is surrounded by HEADERs text.
If you have a properly formatted email, you can use Mail helper methods:
mail = Mail.new(email_string)
mail.text_part # finds the first text/plain part
mail.html_part # finds the first text/html part
This doesn't always work if you have e.g. single part messages (text only) or receive email from the internet at large since you can't rely on formatting from every client out there. Believe me, I've learned the hard way.
looks like you've got a multipart email, so you can use
mail.parts[0].body.decoded
These will probably come in handy too:
mail.multipart?
mail.parts.length
The gem documentation at github is pretty decent
With the mail gem, you can do:
text = mail.multipart? ? mail.text_part.decoded : mail.body.decoded`
Add the mail gem and just use email body format with mail.parts[1].body.decoded.
I'm trying to implement the "blog this" function from Flickr using the BloggerAPI to my pl/sql based CMS.
When Flickr sends me the posting transaction, the HTTP transaction looks like this:
POST /pls/website/!pkg.procAPI HTTP/1.1
Host: www.mydomain.com
Accept: */*
User-Agent: Flickr
Content-Type: text/xml; charset=utf-8
Content-Length: 1220
Expect: 100-continue
<?xml version="1.0" encoding="utf-8"?>
<methodCall>
<methodName>blogger.newPost</methodName>
<params>
<param><value><string>NO_APP_KEY</string></value></param>
<param><value><string>1</string></value></param>
<param><value><string>markj</string></value></param>
<param><value><string>markj</string></value></param>
<param><value><string>This is a test post from <a href="http://www.flickr.com/r/testpost"><img alt="flickr" src="http://www.flickr.com/images/flickr_logo_blog.gif" width="41" height="18" border="0" align="absmiddle" /></a>, a fancy photo sharing thing.</string></value></param>
<param><value><boolean>1</boolean></value></param>
</params>
</methodCall>
But my server is responding with an HTTP-400 Bad Request and the error message is "Signature Mismatch or Missing '='" and my pl/sql procedure never gets a chance to process the request. I suspect that the flexible parameter passing is getting hosed when looking at the message, but I don't know how else
The process to get the available blogs seems to work ok, but the content of the request doesn't have all the html entities as part of the message:
POST /pls/website/!pkg.procAPI HTTP/1.1
Host: www.mydomain.com
Accept: */*
User-Agent: Flickr
Content-Type: text/xml; charset=utf-8
Content-Length: 304
<?xml version="1.0" encoding="utf-8"?>
<methodCall>
<methodName>blogger.getUsersBlogs</methodName>
<params>
<param><value><string>NO-APP-KEY</string></value></param>
<param><value><string>mark</string></value></param>
<param><value><string>markj</string></value></param>
</params>
</methodCall>
Is there a way to get the xml data from the body of the http request directly? or some other approach I'm over looking?
Thanks,
Mark.
I opened a service request with Oracle and they confirmed that mod_plsql does not support retrieving httpheader variables. Here is the discussion I had on the SR:
ISSUE ANALYSIS
I need to confirm it, but Mark conclusion so far looks right to me,i.e. MOD_PLSQL is always invoking and processing PLSQL procedures and there is no way to read the raw HTTP request because MOD_PLSQL parses the request and checks if there is a PLSQL procedure with this name and if there are arguments to pass. If there are no arguments to pass but we are providing something else like the XML document, MODPLSQL gets puzzled and thinks this is a new pair of parameter and value when this is not really the case.
ANSWER
No, it is not possible to do it because MOD_PLSQL just treats requests with parameters which can be parsed and translated as a PLSQL procedure call with several arguments. MOD_PLSQL has no concept of a "httprequest" variable containing the whole request in the same way java has the HTTPRequest object
ISSUE ANALYSIS
Got the confirmation unless we pass it as a parameter we can not read it from MOD_PLSQL. In other words, if we pass the XML page in the HTTP request body we need to use something like java where we can treat the request in raw mode and we can read any HTTP header and the http body without restrictions of any kind.
Can the xml be sent as a file attachment? In other words change:
Content-Type: text/xml; charset=utf-8
to
Content-Type: multipart/form-data, boundary=AaB03x
Then add this before the xml:
--AaB03x
content-disposition: form-data; name="xmlfile"; filename="myfile.xml"
Content-Type: text/xml
And this after the xml:
--AaB03x--
Now, you set up the procedure for a file upload, as explained in this article:
Files, Uploads, and Downloads with Web PLSQL
Use UTL_HTTP
You can use the UTL_HTTP package to do this.
UTL_HTTP.read_text(
r IN OUT NOCOPY resp,
data OUT NOCOPY VARCHAR2,
len IN PLS_INTEGER DEFAULT NULL);
"The UTL_HTTP package supports HTTP 1.1 chunked transfer-encoding. When the response body is returned in chunked transfer-encoding format as indicated in the response header, the package automatically decodes the chunks and returns the response body in de-chunked format."
http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96612/u_http.htm
I'm encountering the same issue MojoMark was (though with a different external application). MojoMark's follow up comment is correct, the read_text information does not answer the question.
Like MojoMark, I am attempting to RECEIVE a POST from an external entity. The PLSQL I'm trying to write is to receive that POST and store it.
I was able to write the outbound POST XML with no problem, but have been unable to set up a procedure to receive it.
The issue appears to be the PLSQL procedure wants a variable name, ie:
http://server/modplsql/testload, POST "data='data'"
However, the body of the POST is just an XML data stream, no "=" assigning a value to a parameter, so the function gets the "Mismatch or Missing '='"" error.
It seems like there should be a way to tell MODPLSQL to just accept accept the post data like a "typical" function call, but I think I'm missing something obvious.
The basics function I'm trying to use to receive the post is:
procedure testload ( DATA in clob ) as
BEGIN
htp.print('Input POST stream was ' || DATA )
end testload;
The only significant difference I can see between the two requests is the "Expect: 100-continue" business. This appers to be a clause in the HTTP 1.1 specification which allows the client to split the request in two. Basically, the client sends the header to the server, and the server must make a choice. If it is "happy" with the header it will give a HTTP 100 response to indicate that the rest of the message will be accepted.
Since you're getting data from Flickr, I'm not sure what level of control you have over the http requests being made by the client. From the server side it may be necessary to make a configuration change to Apache, or it may be a bug in mod_plsql that's popping up with the "!" flexible parameter marker.
Either way, the current blogger api is not like this. You probably should move to the new GData API.