How can i send an inline images using Google API, here is my sameple code
Kindy let me know what am i missing ?
String email =
"Content-Type: multipart/related; boundary:\"multipart_related_boundary\"\r\n" +
"MIME-Version: 1.0\r\n" +
FROM_ME +
TO + toAddress + "\r\n" +
SUBJECT + "welcome" + "\r\n"
+ "--multipart_related_boundary" + "\r\n" +
"Content-type: image/gif; name=\"083.gif\"\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-ID: <083.gif>\r\n" +
"Content-Disposition: inline\r\n"
+ "--multipart_related_boundary" + "\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-Type: text/html; charset=utf-8\r\n" +
CONTENT_TRANSFER_ENCODING_QUOTED_PRINTABLE +
"<html><body><img src=\"cid:083.gif\"/> welcome " +
"</body></html>\r\n\r\n";
byte[] converted = Base64.encodeBase64(email.getBytes());
String encodedStr = new String(converted);
encodedStr = encodedStr.replace("/", "_").replace("+", "-");
MediaType mediaType = MediaType.parse(APPLICATION_JSON);
RequestBody body = RequestBody.create(mediaType, RAW + encodedStr + END_BRACKET);
Request request = new Request.Builder()
.url(HTTPS_WWW_GOOGLEAPIS_COM_GMAIL_V1_USERS_ME_MESSAGES_SEND).post(body)
.addHeader(AUTHORIZATION,
BEARER + gmailAuthService.getRefreshToken(token).getAccessToken())
.addHeader(CONTENT_TYPE, "multipart/related; boundary:\"multipart_related_boundary\"").build();
Response response = okHttpClient.newCall(request).execute();
Finally in my gmail, i am not able to seethe inline image.
You are including the image section of your MIME message, but not the image itself.
After the Content-ID: <083.gif> and Content-Disposition: inline headers you need to include the actual image. Specifically, you probably want to add a Content-Transfer-Encoding: base64 header to that section and include a base64 encoded image payload.
An easy way to see how it could/should work is to use Gmail to email yourself a short test email with a small image. Then, in Gmail (Web UI) go to the message options (near the Reply button) and select "Show Original". That will show you exactly how the MIME message is built.
Related
I am trying to integrate fedex api's into ReactJS or rather NextJS Application. So far I have tried using fetch and XMLHttpRequest. Below is the code that I tried using XHR:
let XHR = new XMLHttpRequest();
XHR.open('POST', 'https://wsbeta.fedex.com:443/web-services', true);
let soapData = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v8="http://fedex.com/ws/vacs/v8">' +
'<soapenv:Header/>' +
'<soapenv:Body>' +
'<v8:ServiceAvailabilityRequest>' +
'<v8:WebAuthenticationDetail>' +
'<v8:ParentCredential>' +
'<v8:Key>XXXXX</v8:Key>' +
'<v8:Password> XXXX</v8:Password>' +
'</v8:ParentCredential>' +
'<v8:UserCredential>' +
'<v8:Key> XXXXX</v8:Key>' +
'<v8:Password> XXXXX</v8:Password>' +
'</v8:UserCredential>' +
'</v8:WebAuthenticationDetail>' +
'<v8:ClientDetail>' +
'<v8:AccountNumber> XXXX </v8:AccountNumber>' +
'<v8:MeterNumber> XXXXX</v8:MeterNumber>' +
'<v8:Localization>' +
'<v8:LanguageCode>EN</v8:LanguageCode>' +
'<v8:LocaleCode>US</v8:LocaleCode>' +
'</v8:Localization>' +
'</v8:ClientDetail>' +
'<v8:TransactionDetail>' +
'<v8:CustomerTransactionId>Services Avaibility</v8:CustomerTransactionId>' +
'</v8:TransactionDetail>' +
'<v8:Version>' +
'<v8:ServiceId>vacs</v8:ServiceId>' +
'<v8:Major>8</v8:Major>' +
'<v8:Intermediate>0</v8:Intermediate>' +
'<v8:Minor>0</v8:Minor>' +
'</v8:Version>' +
'<v8:Origin>' +
'<v8:PostalCode>400061</v8:PostalCode>' +
'<v8:CountryCode>IN</v8:CountryCode>' +
'</v8:Origin>' +
'<v8:Destination>' +
'<v8:PostalCode>560055</v8:PostalCode>' +
'<v8:CountryCode>IN</v8:CountryCode>' +
'</v8:Destination>' +
'<v8:ShipDate>2019-05-21</v8:ShipDate>' +
'<v8:CarrierCode>FDXE</v8:CarrierCode>' +
'</v8:ServiceAvailabilityRequest>' +
'</soapenv:Body>' +
'</soapenv:Envelope>';
XHR.setRequestHeader('Content-Type', 'text/xml');
XHR.setRequestHeader('Access-Control-Allow-origin', '*')
XHR.onreadystatechange = function() {
if(XHR.readyState == 4) {
if(XHR.status == 200) {
console.log(soapData)
}
}
}
XHR.send(soapData)
I get different HTTP error for e.g. (405, 501, 400). Along with this I am getting CORS error which is as follows:
Access to XMLHttpRequest at 'https://wsbeta.fedex.com/web-services' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
For CORS I have tried mode cors in fetch request and with XHR I have set header to Access-Control-Allow-Origin as *, but I am still getting the same error.
I have also installed the extension from chrome web store which has solved the CORS problem yesterday but today I am again facing the same. I have tried to uninstall and reinstall the extension already.
I have also tried adding
Any help would be appreciated.
After the AppEngine's Files API Service Turndown, now we cannot directly create and write blob. Now how to copy/transfer Blobs from one app to another?
To "write" blobs, you can use blob upload to post blobs to your receiving app. To do this you have to post a multipart encoded file using an upload_url of the receiving app.
def post_blob(url, blob_name, blob):
CRLF = '\r\n'
BOUNDERY = '--Th15-Is-ThE-BoUnDeRy--'
payload = '--' + BOUNDERY + CRLF
payload += 'Content-Disposition: form-data; name="file"; filename="%s"' \
% blob_name + CRLF
payload += 'Content-Type: %s' % mimetypes.guess_type(blob_name)[0] + CRLF
payload += CRLF
payload += blob + CRLF
payload += '--%s--' % BOUNDERY + CRLF
urlfetch.fetch(
url=url,
payload=payload,
method=urlfetch.POST,
deadline=40,
follow_redirects=False,
headers={'Content-Type': 'multipart/form-data; boundary=%s' % BOUNDERY)}
)
url = get_receiving_app_blobstore_upload_url() # request upload url
blob_info = blobstore.BlobInfo.get(blob_key)
blob_reader = blobstore.BlobReader(blob_key)
post_blob(url, blob_info.filename, blob_reader.read())
In the receiving app you have to create two handlers:
to request the upload url using blobstore.create_upload_url()
to handle the above post
I am using curl library for email sending.
I am able to send email successfully. I can see FROM, Subject and body properly at receiving end.
Now my need is for attachment in the email.
I have followed in this way:
http://msdn.microsoft.com/en-us/library/ms526560(v=exchg.10).aspx
static const char *text[]={
"Date: Wed, 06 Feb 2013 12:30:30 +1100\n",
"To: " RECIPIENT "\n",
"From: " MAILFROM "\n",
"MIME-Version: 1.0",
"Content-Type: multipart/mixed",
"boundary=""XXXXX""\n",
"Subject: email example message\n",
"--XXXXX",
"\n", /* empty line to divide headers from body, see RFC5322 */
"The body of the message starts here.\n",
"Check RFC5322.\n",
"--XXXXX",
"Content-Type: text/plain" "\n",
"Content-Disposition: attachment" "\n",
"filename="FILE_PATH "\n",
"--XXXXX--",
NULL
};
They are suggesting RFC5322. But in that I could not find anything like attachment.
Is it correct? Any other way using libcurl + C language is also welcomed.
I think the person named as Jorge has asked same kind of question on october 13,2012. But the answer is not there.
The easiest way is to encode using something like base64 encoding which turns binary data into ASCII characters that are able to be sent via email. base64 encode the file and insert the string as below. Replace everything in caps with the correct stuff.
--XXXXboundary text
Content-Type: application/FILETYPE; name="FILENAME"
Content-Disposition: attachment; filename="FILENAME"
Content-Transfer-Encoding: base64
STRINGFROMBASE64ENCODING
Heres a thread on base64: How do I base64 encode (decode) in C?
I think you are right, but why did you attached a null file? I think you need put something in the final attachment body apartment.
For example:
--XXXXboundary text
Content-Type: text/plain;
Content-Disposition: attachment;
filename="test.txt"
this is the attachment text ---- this is attachment content
--XXXXboundary text--
Maybe you should take a look at libquickmail (http://sf.net/p/libquickmail/).
It does all the magic needed to attach files and it uses libcurl for the SMTP transport (or even without libcurl in libquickmaillight).
It can be done as below;
static const char *payload_text[] = {
"To: " TO "\r\n",
"From: " FROM "(Example User)\r\n",
"Cc: " CC "(Another example User)\r\n",
"Subject: SMTPS Example\r\n",
"Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n",
"User-Agent: My eMail Client\r\n",
"MIME-Version: 1.0\r\n",
"Content-Type: multipart/mixed;\r\n",
" boundary=\"------------030203080101020302070708\"\r\n",
"\r\nThis is a multi-part message in MIME format.\r\n",
"--------------030203080101020302070708\r\n",
"Content-Type: text/plain; charset=utf-8; format=flowed\r\n",
"Content-Transfer-Encoding: 7bit\r\n",
"\r\n", /* empty line to divide headers from body, see RFC5322 */
"The body of the message starts here.\r\n",
"\r\n",
"It could be a lot of lines, could be MIME encoded, whatever.\r\n",
"Check RFC5322.\r\n\r\n",
"--------------030203080101020302070708\r\n",
"Content-Type: text/plain; charset=utf-8; format=flowed\r\n",
" name=\"send.c\"\r\n",
"Content-Type: text/plain; charset=utf-8; format=flowed\r\n",
"Content-Disposition: attachment;\r\n",
" filename=\"abc.txt\"\r\n",
"\r\n",
"bla bla file content is here\r\n",
"--------------030203080101020302070708--\r\n",
NULL
};
I've ported the google analytics server side code over into my Python GAE application. Everything is working great, except for language tracking. I'm wondering if anyone here who has used google analytics on the server side has had success tracking languages.
The relevant bit of code is:
utm_url = utm_gif_location + "?" + \
"utmwv=" + GA_VERSION + \
"&utmn=" + str(randint(0, 0x7fffffff)) + \
"&utmhn=" + urllib.quote(domain) + \
"&utmsr=" + '-' + \
"&utme=" + '-' + \
"&utmr=" + urllib.quote(document_referer) + \
"&utmp=" + path + \
"&utmac=" + GA_ACCOUNT + \
"&utmcc=__utma%3D999.999.999.999.999.1%3B" + \
"&utmvid=" + visitor_id + \
"&utmip=" + ip
headers = {
'User-Agent': req.get('ua'),
'Accept-Language': req.get('lang')
}
httpresp = urlfetch.fetch(
url = utm_url,
method = urlfetch.GET,
headers = headers
)
if httpresp.status_code == 200:
logging.info("GA success: %s(%s)\n%s" % (utm_url, headers, httpresp.headers) )
else:
logging.warning("GA fail: %s %d" % (utm_url, httpresp.status_code) )
And here is a little debugging output which shows that I'm sending the Accept-Language header:
GA success: http://www.google-analytics.com/__utm.gif?utmwv=4.4sh&utmn=1306014991&utmhn=XXXXXXXXXXXXX.com&utmsr=-&utme=-&utmr=-&utmp=XXXXXXXXXXXXXXXXXXXXXXXXXX&utmac=MO-XXXXX-XX&utmcc=__utma%3D999.999.999.999.999.1%3B&utmvid=XXXXXXXXXXXXXXXXXX&utmip=XXX.XXX.XX.XX({'Accept-Language': u'en-us', 'User-Agent': u'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A405'})
{'content-length': '35', 'x-google-cache-control': 'remote-fetch', 'x-content-type-options': 'nosniff', 'age': '93451', 'expires': 'Wed, 19 Apr 2000 11:43:00 GMT', 'server': 'GFE/2.0', 'last-modified': 'Wed, 21 Jan 2004 19:51:30 GMT', 'via': 'HTTP/1.1 GWA', 'pragma': 'no-cache', 'cache-control': 'private, no-cache, no-cache=Set-Cookie, proxy-revalidate', 'date': 'Wed, 22 Feb 2012 16:25:04 GMT', 'content-type': 'image/gif'}
(I've XXXX'd stuff to protect the innocent).
As I said, everything is working great (locations, hit count, user agent), except languages. They are all being counted as "not set".
Any ideas?
The language attribute that Google Analytics tracks isn't from headers.
Rather, it's passed directly in the URL request to __utm.gif as the utmul attribute.
So, my computer sets utmul=en-us, using the navigator.language or navigator.browserLanguage attributes (which it seems like it makes lower case.)
In your case, that means you just need to add this line to your __utm.gif constructions:
"&utmul=" + req.get('lang')
I am trying to implement Xmpp protocol in silverlight and trying to connect to Facebook, here I am getting everything correct until <challenge .. > obtained from server.
I am using X Facebook platform authentication.
I have done this with following code:
byte[] ch = Convert.FromBase64String(message.challenge);
string challenge = System.Text.Encoding.UTF8.GetString(ch, 0, ch.Length);
string response = "";
long callId = DateTime.UtcNow.Ticks;
MD5 md = new MD5();
String signature1 = "api_key=203366556348506"
+ "call_id=" + callId
+ "method=auth.xmpp_login"
+ param[2]
+ "session_key=" + messageClient.SessionKey
+ "v=1.0"
+ messageClient.AppSecret;
md.Value = signature1;
response = "method=auth.xmpp_login&api_key=203366556348506&session_key=bc6d6e00462cc2bb73a824bd.4-100001565408667&call_id=" + callId + "&sig=c47d741cb8f18c4e78b990f48e2f63aa&v=1.0&" + param[2];
message.Request = "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(response)) + "</response>";
this.messageClient.SendMessageAsync(message);
But I am getting following message from server:
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
Please let me know where I am going wrong.
Try following code:
String signature1 = "api_key=" + messageClient.ApiKey
+ "call_id=" + callId
+ "method=auth.xmpp_login"
+ param[2]
+ "session_key=" + messageClient.SessionKey
+ "v=1.0"
+ messageClient.AppSecret;
md.Value = signature1;
response = "method=auth.xmpp_login&api_key=" + messageClient.ApiKey + "&session_key=" + messageClient.SessionKey + "&call_id=" + callId + "&sig=" + md.FingerPrint.ToLower() + "&v=1.0&" + param[2];
I have changed response string to the one above.
This has returned success for me. Hope this will help you.