How do I forward a mail message as an attachment in MS Graph? - email

I'm retrieving all the messages from a given mailbox, and if one of them contains problematic attachments, I want to send an email to the sender of that message, explaining the problem, and including the original email as an attachment.
I need to either put the message into a stream, or save it to the filesystem. I imagine the former would be better, but I can't see any methods that can do that.

How big are the attachments that you want to forward? With the Graph there is a 4MB limit that you will hit with some of the endpoints that will restrict the methods you can use to do this. Eg if all the Messages are under 4MB then you could either attachment them as an Item attachment https://learn.microsoft.com/en-us/graph/api/message-post-attachments?view=graph-rest-1.0&tabs=http but for your purposes you'll loose fidelity on things like Internet Message headers which won't help with working out what's gone wrong with the message. Probably what you want to do is download the message first as MIME https://learn.microsoft.com/en-us/graph/outlook-get-mime-message save it as an Eml file and then attach that file. If you need to deal with 4MB+ emails you need to check the size and use https://learn.microsoft.com/en-us/graph/outlook-large-attachments?tabs=http when necessary.

Related

Content-type issue for email attachments mule

I'm using Mule's IMAP connector to read email attachments. I pretty much follow this. It all works fine, but my problem is that there are couple of end users who now tend to send the emails with attachments to us, but with Content-type as 'text/csv' or 'application/octet-stream' in which case Mule is unable to recognise/parse the attachments. The email client like outlook has no problems downloading the files. But does not work with Mule code - probably, the content-type to be blamed but is there a way I can get over this without demanding a change from the end user?
Here is the code that reads the attachments:
<expression-transformer doc:name="Read Attachments and set them as payload"
name="returnAttachments">
<return-argument evaluator="attachments-list"
expression="*" />
</expression-transformer>
<imaps:inbound-endpoint host="${email.server.host}"
port="${email.port}" responseTimeout="10000"
doc:name="IMAP" connector-ref="IMAPS" password="${email.pwd}"
transformer-refs="returnAttachments" user="${email.user}"
disableTransportTransformer="true" />
<!-- The code below does not work when the emails arrived have content type other the "multipart/mixed"-->
<set-variable variableName="fileName" value="#[groovy:payload.name]"
doc:name="fileName" />
As mentioned this one recognises the email and attachments when the content type(header) of the email is "mutipart/mixed". Does not work otherwise. Should I be asking the client to set the content type ?
Your question does not explain what exactly you're trying to do. You can send anything through e-mail. Each attachment is marked with a corresponding MIME type to indicate what sort of data format it contains -- is that an image, or a ZIP file, or perhaps a PDF document?
What is your application doing, and what reaction do you expect when I send, say, a holiday picture as an attachment? What should it do if I attach my bank's statement?
These questoins are about the business logic, about the real purpose of your project. This question does not contain any data about that, unfortunately.

How to retrieve the .xml extension attachments from mail by using MailCore to Sample iPhone app

How to retrieve the .xml extension attachments from mail by using MailCore for iphone?
I used MailCore to download the attachments from my mail to my sample iPhone app. I getting Inbox subjects from my mail that subjects I sort to get particular mail subject and mail attachments.
The problem is I got particular mail subject but not attachments. I used below code to get attachments from mail but it's not working.
NSArray *Array=[msg attachments];
CTBareAttachment *ctbaratt=[Array objectAtIndex:0];
CTCoreAttachment *ctcoreatt=[ctbaratt fetchFullAttachment];
but I'm getting :
Array count is zero
Please share your ideas.
This could be for a few reasons:
1)It is possible that you're not downloading enough information about the CTCoreMessage. When making a request to download the CTCoreMessages you must specify what information you want by specifying the correct fetch attributes.
For example:
[core_folder messagesFromSequenceNumber:from to:to withFetchAttributes: CTFetchAttrEnvelope | CTFetchAttrBodyStructure]
should populate the information about the attachments.
When fetching a message from IMAP, the command will specify exactly what information it wants.
you can see what is being fetched by enabling MailCore Logging as follows:
MailcoreEnableLogging();
[core_folder messagesFromSequenceNumber:from to:to withFetchAttributes: CTFetchAttrEnvelope | CTFetchAttrBodyStructure];
MailcoreDisableLogging();
You will see commands of the format
<command number> <UID> <Command> (<requested structure>)
I imagine you will see something like this:
1 UID FETCH (ENVELOPE)
You should ensure that inside the () either BODY or BODY[2] or RFC822 as these will contain information about attachments.
When you see what is actually being fetched you can read the RFC, if you are dealing with mailcore and IMAP then it is well worth the investment in time.
2)Failing that, perhaps your CTCoreAccount and/or CTCoreFolder are not connected, thus preventing the CTCoreMessage from having a valid mailimapsession and being unable to download the attachment information. If an attribute inside a CTCoreMessage is not available then libetpan should download it on request. The fact that is it not suggests that your account or folder may be not valid or connected.

How to automatically save emails to ascii files?

I have a data stream that will be sent as daily emails containing temperature and wind speed from a measurement site. I would like to to automatically filter out these emails from the other emails I receive, then save the email body content to its own text file. Each text file must have a distinct file name; for example it could include the time that the email was sent or received. All files must all end up in a chosen directory. And ideally the process would be robust enough that it could run unattended for weeks. Our email system is Outlook but I could choose to send the email to my gmail account, for example. What is the big picture of how to do this?
Bigger picture: create a VBA script that runs on the Items_ItemAdd event, which fires whenever an email arrives.
Specifics: Use the solution on this page, but in the Items_ItemAdd routine change the olSaveAsMsg to olSaveAsTxt to get the text format you want.
Note that the file name format in the example should match what you need, but you'll need to add criteria to the Items_ItemAdd routine to check that the message is one that you want to save. For example, you could read the Item.Subject property.
it means you are working with exchange, i suggest to use imap protocol to read the mails, and you will be able to save the body.

How to set up an email server that will accept a URL in the subject of an email and respond with a copy of that webpage

I'm trying to piece out how difficult it would be to set up an email server that will accept a URL as the subject of an email and respond with an attached copy of said webpage, or element(s) of that webpage (ie, an image from the page, or all of the videos on the page).
I don't necessarily need the code written for me, but would appreciate if someone could suggest a starting point.
I have very little web-programming knowledge (some C++, some Actionscript), which is partly why I don't even know where to begin.
There is several ways to achieve this.
In most unix MTAs you can set up an alias to pipe all messages for some address through a program.
This program need to parse the message header for the "from" and "subject", fetch the url and sent it back.
You can also do this with a program like fetchmail, so you dont even need to make something in the server side.
Finally, several languages have wonderful libraries fetch the mail using POP3, parse it, fetch the URL from the subject and compose a new mail message. Should be no more than 100 code lines with perl or python.

Embed indentifier within an Email

I am trying to embed an ID into an email so that when a recipient replies to an email that my system sends out, my system can pick it up and match the two together.
I have tried appending a custom header, however this is stripped out when the user replies.
I have tried embedding an HTML comment within the email, but outlook does not seem to keep comments when a reply email is created.
Worst case scenario, I can manually try and match the sent and received emails by time span or have a visible tag within the message body.
Does anyone know of a more elegant solution?
Thanks in advance
Email messages already contain such an identifiers, called Message-ID. And there's even a way to send which message you're replying to by sending that ID in a header called In-Reply-To. That's done by pretty much all email clients, that's how they usually do their threading.
It's defined in RFC 822 (yep that's pretty old) and probably re-defined and refined in more modern versions of that.
I have seen a method that includes a one byte image with a unique name that's linked to the user. When they view the email and download the images, your HTTP server will record a hit for that unique image. Of course the user needs to display images, but you can include a message in the body asking them to display the images. We actually include content in an image so they need to show images.
If your incoming e-mail can handle +foo or -foo suffixes, use that.
Many e-mail systems can route user+foo#example.com or user-foo#example.com
to user#example.com. You can replace foo with some kind of identifier.
Several mailing list servers use this for tracking bounces.
While I can't say for certain, my investigation in that sort of matter some time ago yielded the following "conclusion":
Headers are transformed a lot
Message bodies are transformed a lot
This is partly because, I suspect, of:
Need to protect users from malicious intentions
Need to perform "targeted marketing"
I have seen "unique codes" flying around in clear text in the email body but I would suggest having a unique identifier embedded in the return address instead.
The usual approach is to place the id in the subject line and/or somewhere visible in the message text and informing the recipient that he should not modify the subject or quote the original mail when responding.