Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Do I use Attachment Class ? #47

Closed
abhiburk opened this issue Jan 24, 2019 · 4 comments
Closed

How Do I use Attachment Class ? #47

abhiburk opened this issue Jan 24, 2019 · 4 comments

Comments

@abhiburk
Copy link

Hey I am implementing Gmail using your package but their is not much info added in this pack document. So at this point I am stuch on Attachment class it would be great if you add more info about how to use that class as I want to download attachment of an email.

@jmatembu
Copy link

jmatembu commented Jan 25, 2019

@abhiburk

The documentation shows you the methods you need to get attachments from an email. Here is some code example assuming you have already retrieved your emails and looping from each to get attachments.

if ($email->hasAttachments()) {
    // Email has attachments
    $attachments = $email->getAttachments()->map(function ($attachment) {
        // Save each attachment to your preferred location
        return $attachment->saveAttachmentTo('path/to/downloaded/attachments', 'filename', 'disk');
    });

    // You now have the paths to the downloaded files in the $attachments variable.
}

The methods availed to you by the package that I have used in the code above are: hasAttachments(), getAttachments(), saveAttachmentTo($path, $filename, $disk)

@abhiburk
Copy link
Author

Okay the one which you share is extremely easy and I gonna replace it with mine one. How I did was

$message = LaravelGmail::message()->get( $gmailID );
        $parts=($message->payload->parts);
        foreach ( $parts as $part ) {
			$body = $part->getBody();
			if ( $body->getAttachmentId() ) {
				$attachment = ( new Attachment( $gmailID, $part ) );
                $attach['attachment'][] = ['fileName'=>$attachment->getFileName(),
                'size'=> $attachment->getSize(),
                'data'=>$attachment->getData()];
			}
        }

My Bad :-P

By the way thank you this package is very helpful.

@dacastro4
Copy link
Owner

@jmatembu thanks for the help!
@abhiburk I'm glad that you find it helpful.

@abhiburk
Copy link
Author

Yes it helped me.
Also I wanted to let you know you can add search function in Message class as their is only in: option available in it. I added it in my code. Hope this helps you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants