473,789 Members | 2,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[reading email] How to save the attachments?

Hello !

I'm looking for a script which allows me to read emails and attachment
from a pop server (then I'll save the email's text in a db and the
attachments on the server).

So I have found this article: http://www.phpit.net/article/read-email-php-pop3/

....
$email = $pop3->get_mail($i) ; // how to get the email
....

But then how do I get the information about my attachments and how can
I save them?

Thanks a lot
Sonja

Jul 26 '07 #1
4 9656
On Jul 26, 3:49 am, sonja.che...@gm ail.com wrote:
Hello !

I'm looking for a script which allows me to read emails and attachment
from a pop server (then I'll save the email's text in a db and the
attachments on the server).

So I have found this article:http://www.phpit.net/article/read-email-php-pop3/

...
$email = $pop3->get_mail($i) ; // how to get the email
...

But then how do I get the information about my attachments and how can
I save them?

Thanks a lot
Sonja
Hi, I may not be the best to respond to this, since I am not familiar
with reading the pop3 e-mail through php at all...but I do know that
with e-mails, attachments are encoded right in the text of the
message, if you save a message and view it in a text editor, you will
likely see the encoded text for your attachement(s).

In the headers for the e-mail message you will find a section similar
to:

------=_NextPart_000_ 001C_01C7C9E5.5 6D0D990
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_ 001D_01C7C9E5.5 6D32380"

Directly above the encoded attachment will be a section similar to:

------=_NextPart_000_ 001C_01C7C9E5.5 6D0D990
Content-Type: application/x-zip-compressed;
name="BELL REPLACEMENT FILES.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="BELL REPLACEMENT FILES.zip"
------=_NextPart_000_ 001C_01C7C9E5.5 6D0D990--

As you notice the content in the mail is encoded as base64.

Where ever the string after the boundary= portion is, will be either
the e-mail message itself, content-type info, or the attachment data
itself. Once you get your text from the e-mail file that is the
encoded attachment, you could probably use:

$file_as_str=ba se64_decode($en coded_string);

which you should then be able to just output the contents of the
base64_decode results to a file to have the attachment file saved, or
place the data in a blob in a mysql table or whatever you would choose
to do with it. Hopefully that makes sense.

Jul 27 '07 #2
Rik
On Thu, 26 Jul 2007 10:49:30 +0200, <so**********@g mail.comwrote:
Hello !

I'm looking for a script which allows me to read emails and attachment
from a pop server (then I'll save the email's text in a db and the
attachments on the server).

So I have found this article:
http://www.phpit.net/article/read-email-php-pop3/

...
$email = $pop3->get_mail($i) ; // how to get the email
...

But then how do I get the information about my attachments and how can
I save them?
Aside from the correct notes from David, there are several packages who
can do this for you without having to reinvent the wheel. Several come to
mind:

1. <http://nl2.php.net/manual/en/ref.imap.php>
2. <http://nl2.php.net/mailparse>
3.
<http://pear.php.net/package/Mail_mimeDecode/docs/latest/Mail_Mime/Mail_mimeDecode .html>

--
Rik Wasmus
Jul 27 '07 #3
Great! Thank you to both of you for the useful information

Jul 31 '07 #4
Rik wrote:
On Thu, 26 Jul 2007 10:49:30 +0200, <so**********@g mail.comwrote:
>Hello !

I'm looking for a script which allows me to read emails and attachment
from a pop server (then I'll save the email's text in a db and the
attachments on the server).

So I have found this article:
http://www.phpit.net/article/read-email-php-pop3/

...
$email = $pop3->get_mail($i) ; // how to get the email
...

But then how do I get the information about my attachments and how can
I save them?

Aside from the correct notes from David, there are several packages who
can do this for you without having to reinvent the wheel. Several come
to mind:

1. <http://nl2.php.net/manual/en/ref.imap.php>
2. <http://nl2.php.net/mailparse>
3.
<http://pear.php.net/package/Mail_mimeDecode/docs/latest/Mail_Mime/Mail_mimeDecode .html>

http://nl2.php.net/mailparse results in a 404

http://us2.php.net/manual/en/ref.mailparse.php works

bill
Jul 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6100
by: PIII450 | last post by:
Hi all, Does anyone know of a class which will read outlook email messages. I need to be able to scan outlook for "non-read" e-mails with a specific subject and then save the attachments and mark the e-mail as "read". I tried working with the am outlook application COM object but could not get it to work. If you have another way to do what I want, without human intervention, I'm open for suggestions. I't goes without saying I want to...
4
3734
by: Paul Schmidt | last post by:
Dear list: I am new to python, and I am trying to figure out the short answer on something. I want to open a POP3 mailbox, read the enclosed mail using the POP3 module, , and then process it using the email module. Environment Python 2.3.4, Mandrake Linux 9.0 patched up the wazoo...
0
1795
by: Karen Grube | last post by:
Hi! I hate to bother you all with this, but I don't know how best to approach a particular task. Here's the deal: Once a month I personally (that is, in my own personal inbox on my company's email server) receive an email from one of our vendors to which is attached a text file (a comma-delimited data file containing the details of our monthly
6
10505
by: c_shah | last post by:
how to save outlook email attachments using VB.net?
10
2199
by: Walshi | last post by:
Hi all, I'm a relative newby to access and VBA etc. My forms and tables etc are working great and saving lots of time...However... I have two databases with the exact same table format. I want db1 to be used to input data by a remote operator, when she is ready I want her to be able to click a control button to email her new data to db2. This new data will be added to the table in db2 ready for further processing.
7
6811
by: Dean Spencer | last post by:
Can anyone help? I am importing Emails from Outlook using the following code: Public Function ScanInbox(SubjectLine As String) Dim TempRst As Recordset Dim OlApp As Outlook.Application Dim Inbox As Outlook.MAPIFolder Dim InboxItems As Outlook.Items Dim Mailobject As Object Set OlApp = CreateObject("Outlook.Application")
2
2649
by: oyster | last post by:
I find that the existing email moudle is some hard for me to understand, especially the part of how to set the CC, BCC and attach the files. Is there any more easy one like this p-code? import easyemail smtpserver=easyemail.server('something') smtpserver.login('usr@gmail.com', pwd) newletter=smtpsever.letter(smtpserver) newletter.sendto= newletter.sendcc=
1
1337
by: Hamayun Khan | last post by:
Hello ! I'm looking for a script which allows me to read emails and attachment from a pop server (then I'll save the email's text in a db and the attachments on the server). So I have found this article: http://www.phpit.net/article/read-email-php-pop3/ .... $email = $pop3->get_mail($i); // how to get the email
1
1423
by: =?Utf-8?B?QnJhc3NpY2FOaWdyYQ==?= | last post by:
Greetings, This question does not seem to fit any of the forum headers so I picked the most general sounding forum I could find. My laptop is running Vista Ultimate. I use yahoo.com for business email and use their web based email client for my business account. Yesterday I received an email with a .pdf attachment. When I went to save the attachment the browser window refreshed but no dialog appeared asking me
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.