I'm sending test mail using ActionMailer. The template is being rendered and mail is being delivered fine. The only problem is the mimepart and other header data is displayed by Google in message body.
Here is the code that mails..
def testing
mail(:to => "apoorvparijat#gmail.com",:subject => "html mailer", :content_type => "text/html") do |format|
format.html { render 'testing' }
format.text { render :text => "bing" }
end
end
and Here's the email received.
----==_mimepart_508fd46252b8c_8023fe595835ad0479a6 Date: Tue, 30 Oct 2012 18:51:38 +0530
Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit
Content-ID: <508fd46254ea7_8023fe595835ad0480b8#Apoorv-Parijats-MacBook-Pro-2.local.mail>
bing ----==_mimepart_508fd46252b8c_8023fe595835ad0479a6 Date: Tue, 30 Oct 2012 18:51:38
+0530 Mime-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding:
7bit Content-ID: <508fd46256465_8023fe595835ad04819c#Apoorv-Parijats-MacBook-Pro-
2.local.mail> Hi bing
column 1 column 2
----==_mimepart_508fd46252b8c_8023fe595835ad0479a6--
Output of the console -
Loading development environment (Rails 3.2.2)
1.9.3-p125 :001 > RankMailer.testing.deliver
I, [2012-10-30T18:51:38.331238 #2050] INFO -- : Rendered rank_mailer/testing.html.erb
(1.8ms)
I, [2012-10-30T18:51:38.333117 #2050] INFO -- : Rendered text template (0.0ms)
I, [2012-10-30T18:51:45.824962 #2050] INFO -- :
Sent mail to apoorvparijat#gmail.com (7484ms)
D, [2012-10-30T18:51:45.825125 #2050] DEBUG -- : Date: Tue, 30 Oct 2012 18:51:38 +0530
From: admin#rankdemon.com
To: apoorvparijat#gmail.com
Message-ID: <508fd462572ec_8023fe595835ad0482c0#Apoorv-Parijats-MacBook-Pro-2.local.mail>
Subject: html mailer
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_508fd46252b8c_8023fe595835ad0479a6
Date: Tue, 30 Oct 2012 18:51:38 +0530
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <508fd46254ea7_8023fe595835ad0480b8#Apoorv-Parijats-MacBook-Pro-2.local.mail>
bing
----==_mimepart_508fd46252b8c_8023fe595835ad0479a6
Date: Tue, 30 Oct 2012 18:51:38 +0530
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <508fd46256465_8023fe595835ad04819c#Apoorv-Parijats-MacBook-Pro-2.local.mail>
Hi bing
<table style="border:1px solid red">
<tr>
<td>column 1</td>
<td>column 2</td>
</tr>
</table>
----==_mimepart_508fd46252b8c_8023fe595835ad0479a6--
=> #<Mail::Message:70255316899740, Multipart: false, Headers: <Date: Tue, 30 Oct 2012 18:51:38 +0530>, <From: admin#rankdemon.com>, <To: apoorvparijat#gmail.com>, <Message-ID: <508fd462572ec_8023fe595835ad0482c0#Apoorv-Parijats-MacBook-Pro-2.local.mail>>, <Subject: html mailer>, <Mime-Version: 1.0>, <Content-Type: text/html>, <Content-Transfer-Encoding: 7bit>>
Don't specify :content_type => "text/html" in your mail method. Since you're using format block, rails will automatically pick up mime type.
MORE DETAILS:
Try this to send out multipart email (ie. both html and text formats of email). Notice the order of formats.
mail(:to => "apoorvparijat#gmail.com", :subject => "html mailer") do |format|
format.text { render :text => "bing" }
format.html { render 'testing' }
end
Related
I'm getting a response in JSON and I'm trying to use the
DeserializeStoreInfoResponse(Storeresponse As String) As String
Dim obj As New JSON_resultStorePos
obj = JsonConvert.DeserializeObject(Of JSON_resultStorePos)(Storeresponse)
the initial response is a HttpResponseMessage and all I need is the JSON string info. When it's a nice neat string in Json format everything deserializes fine into the JSON_resultStorePos table. But I'm trying to view the initial response to see if everything is there in their response and can't quite figure out where the actual JSON content is written in the HttpResponseMessage?
here's some of the response:
?aResponse
{StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Strict-Transport-Security: max-age=7776000; includeSubDomains
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Pragma: no-cache
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Cache-Control: no-store
Date: Thu, 10 Nov 2016 13:37:39 GMT
Set-Cookie: SERVERID=04-97JSNQEU5RG2G; path=/; HttpOnly
Server: Apache
X-Powered-By: Express
Content-Length: 71
Content-Type: application/json
?aResponse.Content
{System.Net.Http.StreamContent}
Headers: {Content-Length: 71
Content-Type: application/json
}
IsBuffered: True
bufferSize: 4096
bufferedContent: {System.Net.Http.HttpContent.LimitMemoryStream}
canCalculateLength: True
content: {System.Net.Http.HttpClientHandler.WebExceptionWrapperStream}
contentConsumed: True
contentReadStream: Nothing
disposed: False
headers: {Content-Length: 71
Content-Type: application/json
How can I see the JSON string I'm deserializing ?
Hi just wondering how I get real data back from the following. I put in this into Oauth 2.0 playgournd:
https://www.googleapis.com/fitness/v1/users/me/dataSources/derive_step_cadence<-raw:com.google.step_count.cumulative:LGE:Nexus 5:bc5f1b97:Step Counter/datasets/8587796212108459505-8587784116108409439
And I get back this:
HTTP/1.1 200 OK
Content-length: 202
X-xss-protection: 1; mode=block
Content-location: https://www.googleapis.com/fitness/v1/users/me/dataSources/derive_step_cadence<-raw:com.google.step_count.cumulative:LGE:Nexus 5:bc5f1b97:Step Counter/datasets/8587796212108459505-8587784116108409439
X-content-type-options: nosniff
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Vary: Origin,X-Origin
Server: GSE
Etag: "hLUJCvL5ZSSqXM3VrwyiV-fn_Cc/UTWu-5kuRnTemL1Tzb1qSZ4O9uk"
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Fri, 06 Feb 2015 04:22:06 GMT
X-frame-options: SAMEORIGIN
Content-type: application/json; charset=UTF-8
{
"minStartTimeNs": "8587784116108409439",
"maxEndTimeNs": "8587796212108459505",
"dataSourceId": "derive_step_cadence<-raw:com.google.step_count.cumulative:LGE:Nexus 5:bc5f1b97:Step Counter
}
Not any useful data.
Am I doing something wrong?
thanks
Russ
Be sure that timestamp that you provide at the end of the endpoint is in nanotime format.
https://www.googleapis.com/fitness/v1/users/me/dataSources/derive_step_cadence<-raw:com.google.step_count.cumulative:LGE:Nexus 5:bc5f1b97:Step Counter/datasets/000000-1720845034000000000
This solution works like a charm
I am trying to run a login REST service in SoapUIPro with jason.
But I am getting the following syntactical error.
It's working fine when I switch to xml
Request
POST http://122.122.232.112/services/public/login HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
Accept: application/json
Content-Length: 115
Host: 122.122.232.112
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
{
"com.abc.dmb.cons.model.LoginInfo": {
"userId": "cons31312061521360",
"password": "Arif#1212"
}
}
Response
HTTP/1.1 400 Bad Request
Date: Fri, 06 Dec 2013 05:02:59 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Accept-Ranges: bytes
Server: abcd.setup.com.au
Content-Type: application/json;charset=ISO-8859-1
Transfer-Encoding: chunked
Connection: close
{"errorCode":"400","errorDescription":"The request sent by the client was syntactically incorrect."}
Please clarify
Cheers
I'm using google api dot net client, and i'm a bit confused.
Following code returns me the entire list of a specific folder (with an Id: XXXXXXXXXXXXXXXXXXXXX).
List<File> result = new List<File>();
FilesResource.ListRequest request = service.Files.List();
request.Q = "'XXXXXXXXXXXXXXXXXXXXX' in parents";
request.MaxResults = 35;
FileList files = request.Fetch();
As example one item of this FileList is
"id": "0B5XhOfl0NZ2cZ1M1aVBPcVlTUTA",
"title": "87BC1CAE-A01C-43A1-BB21-BE3DA6D6C7DC"
If i change the query, searching for a title, i receive always an empty FileList.
List<File> result = new List<File>();
FilesResource.ListRequest request = service.Files.List();
request.Q = "title = '87BC1CAE-A01C-43A1-BB21-BE3DA6D6C7DC'";
request.MaxResults = 35;
FileList files = request.Fetch();
It does'nt matter, if the operator is '=' or 'contains', or by searching only a part of the directory name:
title contains '87BC1CAE'
I receive correct results only by searching for IDs.
Following code works flawless:
File file = service.Files.Get(fileId).Fetch();
Console.WriteLine("Title: " + file.Title);
Console.WriteLine("Description: " + file.Description);
Console.WriteLine("MIME type: " + file.MimeType);
Help please :)
#AliAfshar
Raw HTTP responses:
1st case (title = '87BC1CAE-A01C-43A1-BB21-BE3DA6D6C7DC')
request.Fetch()
TestGoogleApi.vshost.exe Information: 0 : DotNetOpenAuth, Version=4.0.0.11165, Culture=neutral, PublicKeyToken=2780ccd10d57b246 (official)
TestGoogleApi.vshost.exe Information: 0 : Preparing to send AssertionFlowMessage (2.0) message.
TestGoogleApi.vshost.exe Information: 0 : Sending AssertionFlowMessage request.
TestGoogleApi.vshost.exe Information: 0 : HTTP POST https://accounts.google.com/o/oauth2/token
TestGoogleApi.vshost.exe Information: 0 : The following required parameters were missing from the DotNetOpenAuth.OAuth2.Messages.AccessTokenFailedResponse message: {error,}
TestGoogleApi.vshost.exe Information: 0 : Received UnauthorizedResponse response.
{Google.Apis.Drive.v2.Data.FileList}
_etag: "\"Q0cVodxX8sh4vfxZTlOyWcmmc0k/vyGp6PvFo4RvsFtPoIWeCReyIC8\""
_items: Count = 0
_kind: null
_nextLink: null
_nextPageToken: null
_selfLink: null
ETag: "\"Q0cVodxX8sh4vfxZTlOyWcmmc0k/vyGp6PvFo4RvsFtPoIWeCReyIC8\""
Items: Count = 0
Kind: null
NextLink: null
NextPageToken: null
SelfLink: null
2nd case ('XXXXXXXXXXXXXXXXXXXXXX' in parents )
request.Fetch()
TestGoogleApi.vshost.exe Information: 0 : DotNetOpenAuth, Version=4.0.0.11165, Culture=neutral, PublicKeyToken=2780ccd10d57b246 (official)
TestGoogleApi.vshost.exe Information: 0 : Preparing to send AssertionFlowMessage (2.0) message.
TestGoogleApi.vshost.exe Information: 0 : Sending AssertionFlowMessage request.
TestGoogleApi.vshost.exe Information: 0 : HTTP POST https://accounts.google.com/o/oauth2/token
TestGoogleApi.vshost.exe Information: 0 : The following required parameters were missing from the DotNetOpenAuth.OAuth2.Messages.AccessTokenFailedResponse message: {error,}
TestGoogleApi.vshost.exe Information: 0 : Received UnauthorizedResponse response.
{Google.Apis.Drive.v2.Data.FileList}
_etag: "\"Q0cVodxX8sh4vfxZTlOyWcmmc0k/Jyx7utsp71-_JwU5RHnI_VZmL5o\""
_items: Count = 1575
_kind: null
_nextLink: null
_nextPageToken: null
_selfLink: null
ETag: "\"Q0cVodxX8sh4vfxZTlOyWcmmc0k/Jyx7utsp71-_JwU5RHnI_VZmL5o\""
Items: Count = 1575
Kind: null
NextLink: null
NextPageToken: null
SelfLink: null
Updated on 2013 Feb 02
Ok excuse me for delay.
i used fiddler and here is captured result:
first request:
POST https://accounts.google.com/o/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=utf-8
User-Agent: DotNetOpenAuth/4.0.0.11165
Host: accounts.google.com
Cache-Control: no-store,no-cache
Pragma: no-cache
Content-Length: 603
Connection: Keep-Alive
grant_type=assertion&assertion_type=http%3A%2F%2Foauth.net%2Fgrant_type%2Fjwt%2F1.0%2Fbearer&assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI0MjYwNjE5OTE1NzktYXEzMHBhcmVsYmpsb3BrMjlqcXFvdjhsdWhic2o3YjdAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvZHJpdmUiLCJhdWQiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20vby9vYXV0aDIvdG9rZW4iLCJleHAiOjEzNjAwNjA0NDMsImlhdCI6MTM2MDA1Njg0M30.dk7Vdu-................-LIw0sFrVko-VWL7-elhz59VQcU_.........
first answer:
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Tue, 05 Feb 2013 09:34:03 GMT
Content-Type: application/json
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Content-Length: 128
{
"access_token" : "ya29.AHES6ZS-...........-a8HRHfMZ-NxXekx",
"token_type" : "Bearer",
"expires_in" : 3600
}
second request:
GET https://www.googleapis.com/drive/v2/files?alt=json&fields=items(id%2Ctitle)%2CnextPageToken&prettyPrint=true&maxResults=2000&q=title%20%3D%20'87BC1CAE-A01C-43A1-BB21-BE3DA6D6C7DC' HTTP/1.1
Authorization: Bearer ya29.AHES6ZS-...........-a8HRHfMZ-NxXekx
Content-Type: application/json; charset=utf-8
User-Agent: TestGoogleApi google-api-dotnet-client/ Win32NT/6.1.7600.0 (gzip)
Host: www.googleapis.com
Accept-Encoding: gzip, deflate
second answer:
HTTP/1.1 200 OK
Expires: Tue, 05 Feb 2013 09:34:04 GMT
Date: Tue, 05 Feb 2013 09:34:04 GMT
Cache-Control: private, max-age=0, must-revalidate, no-transform
ETag: "Q0cVodxX8sh4vfxZTlOyWcmmc0k/vyGp6PvFo4RvsFtPoIWeCReyIC8"
Content-Type: application/json; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Content-Length: 17
Server: GSE
{
"items": []
}
as you see items count is 0.
If i make the same request via web interface
https://developers.google.com/drive/v2/reference/files/list it gives me 2 items, as it should be.
This is made with https://developers.google.com/oauthplayground/
GET /drive/v2/files?alt=json&fields=items(id%2Ctitle)%2CnextPageToken&prettyPrint=true&maxResults=2000&q=title%20%3D%20'87BC1CAE-A01C-43A1-BB21-BE3DA6D6C7DC' HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: OAuth ya29.AHES6ZSDr7bDFMQxjR........ObzyEhkzQmN
HTTP/1.1 200 OK
Content-length: 220
Via: HTTP/1.1 GWA
Content-location: https://www.googleapis.com/drive/v2/files?alt=json&fields=items(id%2Ctitle)%2CnextPageToken&prettyPrint=true&maxResults=2000&q=title%20%3D%20'87BC1CAE-A01C-43A1-BB21-BE3DA6D6C7DC'
X-content-type-options: nosniff
Etag: "Q0cVodxX8sh4vfxZTlOyWcmmc0k/oUg90Ml6_g3EsaXCogiJOEMkZ-M"
X-google-cache-control: remote-fetch
-content-encoding: gzip
Server: GSE
Reason: OK
X-xss-protection: 1; mode=block
Cache-control: private, max-age=0, must-revalidate, no-transform
Date: Tue, 05 Feb 2013 15:30:09 GMT
X-frame-options: SAMEORIGIN
Content-type: application/json; charset=UTF-8
Expires: Tue, 05 Feb 2013 15:30:09 GMT
{
"items": [
{
"id": "0B5XhOf....VlTUTA",
"title": "87BC1CAE-A01C-43A1-BB21-BE3DA6D6C7DC"
},
{
"id": "0B5XhO....EbGRLVVVReGM",
"title": "87BC1CAE-A01C-43A1-BB21-BE3DA6D6C7DC"
}
]
}
Thank you very much, i really appreciate your help
Looks like the confusion is due to the fact that you are using a service account in your code, but comparing the results with what you see in the web interface.
When using the web interface or the OAuth Playground, you are authorizing the app to use your personal account and not a service account. The service account doesn't have access to the same files you have access to, as it is actually an application-owned account.
If you want to use a service account to access your files, you should perform domain-wide delegation as explained at https://developers.google.com/drive/delegation
This still doesn't explain why some queries return results and others don't, but please try everything again without using service accounts and update the issue if things still don't work as expected.
I have a sned mails system.I use the EventMachine to send the mails.But when I recived the mail which I sent,I just got the html code,But html view.
How to set the conent_type = 'text/html' in EventMachine?
THX
%w(rubygems eventmachine mailfactory).each{|lib|require lib}
#gem install mailfactory -V
EM.run{
mail = MailFactory.new
mail.to = 'xxx#gmail.com'
mail.from = 'dongyuwei#weibo.com'
mail.subject = 'hi!'
#mail.text = 'hello world'
mail.html = '<h1>hello world</h1>weibo.com'
email = EM::P::SmtpClient.send(
:from=>mail.from,
:to=>mail.to,
:content=>"#{mail.to_s}\r\n.\r\n",
:header=> {"Subject" => mail.subject},
:domain=>"session.im",
:host=>'smtp.gmail.com',
:port=>587,
:starttls=>true,
:auth => {
:type=>:plain,
:username=>"xxxx#gmail.com",
:password=>"yyyyyyy"
},
:verbose => true
)
email.callback{
puts 'Email sent!'
}
email.errback{ |e|
puts 'Email failed!'
}
}
When you build the email, build it as multi-part with text and html parts. You'll need to set all the headers, etc. Here's an example mail message:
Date: Wed, 13 Apr 2011 17:44:05 -0400
From: Me <me#example.com>
To: User Name <user#example.com>
Message-ID: <7672767637637#example.com>
Subject: test email
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="4da61925_46111ba5_b0f1"
Content-Transfer-Encoding: 8bit
--4da61925_46111ba5_b0f1
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Message here!
--4da61925_46111ba5_b0f1
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
<div>
html message here!
</div>
--4da61925_46111ba5_b0f1--