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

error when the email has no html ? #24

Closed
JonahKlimack opened this issue Jul 23, 2018 · 0 comments
Closed

error when the email has no html ? #24

JonahKlimack opened this issue Jul 23, 2018 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@JonahKlimack
Copy link
Contributor

Pretty simple error, trying to fix it myself but I'm sure you could do it much quicker.

If the email is ONLY plain text with no html, we get an error. If the email has html in it, then all works fine.

<?php

namespace App\Http\Controllers;


use LaravelGmail;
use Illuminate\Http\Request;

class TestGmailApiController extends Controller
{


	/**
	 * testing
	 *
	 * @return void
	 */
	public function test ()
	{
		//$messages = LaravelGmail::message()->from('someone-who-sends-html-emails@email.com')->take(5)->all();
		
		$messages = LaravelGmail::message()->from('someone-who-sends-plain-text-emails@email.com')->take(5)->all();

		foreach ($messages as $message) 
		{

			dump($message->load()->getHtmlBody());
			dump($message->load()->getRawPlainTextBody());
			dump($message->load()->getPlainTextBody());


		}
	}


The error message is

Whoops, looks like something went wrong.
1/1
ErrorException in UserRefreshCredentials.php line 91:
Your application has authenticated using end user credentials from Gooogle Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/.

Great, now gmail keeps asking for a service account... might as well be asking me to create a rocket and successfully launch it into space. Thanks Google.

Anyway,
I can't give you the error message, but I spent time on it so I know the problem.

the problem is $body is null on line 376 in Services/Message/Mail.php

	public function getBody( $type = 'text/plain' )
	{
		$part = $this->getBodyPart( $type );
		$body = $part->getBody();

		return $body->getData();
	}

basically in this case something goes null that maybe you're not handling when getBodyPart() or Get Part() is called

when the email is plaintext only..
have you ever tried this on a plaintext email?

@dacastro4 dacastro4 added the bug Something isn't working label Nov 10, 2018
@dacastro4 dacastro4 self-assigned this Nov 10, 2018
dacastro4 added a commit that referenced this issue Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants