how to extract dkim value of Authentication-Results field from message header using java mail - jakarta-mail

I want to extract dkim value of Authentication-Results field from email header.
I tried with below code and below is the response of code for reference.
code:
String Auth[] =messages[(int) i].getHeader("Authentication-Results");
System.out.println("Authentication-Results : " +
Arrays.toString(Auth) );
output:
Authentication-Results:mta4458.mail.bf1.yahoo.com from=xyz.com;
domainkeys=neutral (no sig); from=xyz-com.20150623.gappssmtp.com;
dkim=pass (ok)
I Want the following output:
dkim=pass

You need to parse the string. It doesn't seem to use the standard MIME format that other headers use so you'll need to write your own parser. The syntax is specified by RFC 5451.

Related

libcurl imaps doesn't returns Header Field "Content-Transfer-Encoding" or "Content-Type"

I have been trying to detect encoding of an email manually, to see whether the email that i have just fetched needed to be base64 decoded or not, but that wasn't a complete solution.
So now I'm trying to download the headers (fields) of an email first, check them what kind of email it is and then proceed to decoding it with base64 in case the header says that it is a base64 encoded email or just skip it if it is a plain text or HTML text.
The problem is that the libcurl commands for fetching these fields doesn't really work, most of the time the "Content-Type" returns just an empty string or says that it is a multipart/alternative but when i check the email manually it is just a plain text which obviously doesn't need to be decoded.??
"Content-Type" field multipart/alternative usually have different parts like text, html, base64 encoded text, attachments etc.
In cases of multipart/alternative the "Content-Transfer-Encoding" field doesn't return anything at all, and this is the most important header field for me to know what it contains.
My imaps request to Gmail account looks like this:
curl_easy_setopt(curl, CURLOPT_URL,"imaps://imap.gmail.com:993/INBOX;UID=33;SECTION=HEADER.FIELDS%%20(Content-Transfer-Encoding%%20Subject%%20From%%20Content-Type)");
Which returns this:
Subject: my subject
From: myname
Content-Type: multipart/alternative; boundary="001a114930a049c6da05dskdls9"
As you can see it doesn't returns the "Content-Transfer-Encoding" field.
This email actually contains the word "Yup" only, so it is a plain text and no attachments, when checked by clicking on the "show original" message in browser.
Sys info:
Linux, C , libcurl, gmail

How can I send a file, for example "exe", with Telnet?

With smtp, i know the commands: "HELO", "MAIL FROM", "RCPT TO", "QUIT", but i don't know how can i attach one file. Anyone can help me ?
telnet smtp.xxxx.xxxx 25
helo xxxx.xxxx
mail from: yyy#xxx.xxx
rcpt to: yy2#xxx.xxx
data
subject: hi
hello
.
quit
This is not something that can be easily done. You probably want to use a library (ex : in python) that will take care of formatting your email according to your needs.
In very brief :
Sending an attachement requires the email to be formatted according to the MIME RFC
A MIME formatted message will use some delimiters to separate the different parts of the message (ex : a plain text part, an HTML part, an attachment part, etc...)
Each MIME part will be prefixed by a header detailing the part content
an attachment part will be identified by a "Content-disposition" header, as detailed in RFC 2183.
The representation of your file will have to be specified using the "Content-Transfer-Encoding" header, described in RFC 2045. A common way to encode files for mail transfer is base64.
If you want to get an idea of how complex it is to generate an email with a valid attachment, you can use your email client to check the source of an email with an attachment (most email clients have this feature). That should eventually convince you to avoid doing this manually :)

Getting more data from messages.get in C#

I'm having trouble getting more than just the snippet for text data for the message I am trying to retrieve using the Gmail API. Here is the piece of test code I am working with:
public string GetMail()
{
GmailService service = (GmailService)HttpContext.Current.Session["service"];
Message messageFeed = service.Users.Messages.List("me").Execute().Messages.First();
UsersResource.MessagesResource.GetRequest getReq = new UsersResource.MessagesResource.GetRequest(service, "me", messageFeed.Id);
getReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Full;
Message message = getReq.Execute();
return message.Raw;
}
For some reason, when I call message.Raw, it is returning null. I am able to retrieve other properties as what the format=minimal setting would based off of the API playground example I was playing with.
However in my code, I am setting the format enum to "full", yet I am still unable to retrieve the full data of the message.
Am I completely missing something here?
Seems like you're mixing up formats and response types. If you want the raw message as a string in Message.raw then you need to set:
getReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw;
If you want the parsed message back (in the "payload" field) then you can use getReq.Format of Full like you have.
Acceptable values are:
"full": Returns the parsed email message content in the payload field and the raw field is not used. (default)
"minimal": Only returns email message metadata such as identifiers and labels, it does not return the email headers, body, or payload.
"raw": Returns the entire email message content in the raw field as a string and the payload field is not used. This includes the identifiers, labels, metadata, MIME structure, and small body parts (typically less than 2KB).
from: https://developers.google.com/gmail/api/v1/reference/users/messages/get

Amazon MWS Connection String Not Working

The connection string below is returning an 'Invalid Address' error. The error message indicates that the API Version is missing, but it is included in the string (see the last parameter). Not sure what the issue is.
https://mws.amazonservices.com/AWSAccessKeyId=[ID Hidden]&Action=GetFeedSubmissionList
&Marketplace=ATVPDKIKX0DER&Merchant=[Merchant Hidden]&Signature=[Signature Hidden]
&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2013-10-17T00:37:34.100Z&Version=2009-01-01
I usually send my MWS calls through a HTTP POST command, because that's the only way to do a SubmitFeed. The following assumes that a GET works at all (I didn't test):
Your call is missing the ? separator between the query and the rest of the URL. So as a minimum, this should read:
https://mws.amazonservices.com/?AWSAccessKeyId....

How to read body of mail using javax.mail.internet.MimeMulitpart

I am trying to read the body contents of a mail and i keep getting the following "Message" string...but not actual body of mail
SentDate : Mon May 21 14:56:47 CAT 2012
From : {FROM}
Subject : TEST
Message :javax.mail.internet.MimeMultipart#320e7a
Any help/advice on what exactly it is i might be missing?
Thanking you in adnvance
Faheem
A mail could be plain text, html or Multipart(text + attachments), Multipart Alternative(text + html) etc.
You have to iterate through each BodyPart to know it's type and then get the content accordingly. This javamail FAQ entry could help you.

Resources