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 500 when sending email "Undefined offset: 1" #1810

Closed
3 tasks done
IxFail opened this issue Mar 2, 2016 · 16 comments
Closed
3 tasks done

Error 500 when sending email "Undefined offset: 1" #1810

IxFail opened this issue Mar 2, 2016 · 16 comments

Comments

@IxFail
Copy link

IxFail commented Mar 2, 2016

Expected Behavior

The mail is send with smtp

Actual Behavior

A 500 error is showing + no mail is send

Before posting this issue, confirm/answer the following:

Snipe-IT version v2.1.0-41-g6d810a9
PHP Version 5.5.9-1ubuntu4.14
Laravel Version 4.2.17

Hi guys,

I have the following issue:

When I try to send an email I get a 500 error
In the logs and debug mod it's saying it's caused by /­vendor/­swiftmailer/­swiftmailer/­lib/­classes/­Swift/­Transport/­Esmtp/­Auth/­NTLMAuthenticator.php:303
The following script is showing in the debug mode:

protected function getDomainAndUsername($name)
  {
    if (strpos($name, '\\') !== false) {
            return explode('\\', $name);
       }

       list($user, $domain) = explode('@', $name);

       return array($domain, $user);

This is my mail.php config:

<?php

return array(

    /*
    |--------------------------------------------------------------------------
    | Mail Driver
    |--------------------------------------------------------------------------
    |
    | Laravel supports both SMTP and PHP's "mail" function as drivers for the
    | sending of e-mail. You may specify which one you're using throughout
    | your application here. By default, Laravel is setup for SMTP mail.
    |
    | Supported: "smtp", "mail", "sendmail"
    |
    */

    'driver' => 'smtp',

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Address
    |--------------------------------------------------------------------------
    |
    | Here you may provide the host address of the SMTP server used by your
    | applications. A default option is provided that is compatible with
    | the Postmark mail service, which will provide reliable delivery.
    |
    */

    'host' => 'mail.company.nl',

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Port
    |--------------------------------------------------------------------------
    |
    | This is the SMTP port used by your application to delivery e-mails to
    | users of your application. Like the host we have set this value to
    | stay compatible with the Postmark e-mail application by default.
    |
    */

    'port' => '587',

    /*
    |--------------------------------------------------------------------------
    | Global "From" Address
    |--------------------------------------------------------------------------
    |
    | You may wish for all e-mails sent by your application to be sent from
    | the same address. Here, you may specify a name and address that is
    | used globally for all e-mails that are sent by your application.
    |
    */

    'from' => array('address' => 'prhc.systeembeheer@companydomain.nl', 'name' => 'Systeembeheer'),

    /*
    |--------------------------------------------------------------------------
    | E-Mail Encryption Protocol
    |--------------------------------------------------------------------------
    |
    | Here you may specify the encryption protocol that should be used when
    | the application send e-mail messages. A sensible default using the
    | transport layer security protocol should provide great security.
    |
    */

    'encryption' => '',

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Username
    |--------------------------------------------------------------------------
    |
    | If your SMTP server requires a username for authentication, you should
    | set it here. This will get used to authenticate with your server on
    | connection. You may also set the "password" value below this one.
    |
    */

    'username' => 'prhc.systeembeheer',

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Password
    |--------------------------------------------------------------------------
    |
    | Here you may set the password required by your SMTP server to send out
    | messages from your application. This will be given to the server on
    | connection so that the application will be able to send messages.
    |
    */

    'password' => '',

    /*
    |--------------------------------------------------------------------------
    | Sendmail System Path
    |--------------------------------------------------------------------------
    |
    | When using the "sendmail" driver to send e-mails, we will need to know
    | the path to where Sendmail lives on this server. A default path has
    | been provided here, which will work well on most of your systems.
    |
    */

    'sendmail' => '/usr/sbin/sendmail -bs',

    /*
    |--------------------------------------------------------------------------
    | Mail "Pretend"
    |--------------------------------------------------------------------------
    |
    | When this option is enabled, e-mail will not actually be sent over the
    | web and will instead be written to your application's logs files so
    | you may inspect the message. This is great for local development.
    |
    */

    'pretend' => false,

);

For the username I even tried the email adres.
The email account does not need a password

I hope you guys can help me.

greetz

@snipe
Copy link
Owner

snipe commented Mar 2, 2016

What is the actual error that's being thrown?

@IxFail
Copy link
Author

IxFail commented Mar 3, 2016

Hi the actual error is Whoops!

Server Error: 500 (Internal Server Error)

In the log I have the following:

[2016-03-03 13:31:37] production.ERROR: exception 'ErrorException' with message 'Undefined offset: 1' in /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php:303
Stack trace:
#0 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php(303): Illuminate\Exception\Handler->handleError(8, 'Undefined offse...', '/var/www/snipei...', 303, Array)
#1 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php(197): Swift_Transport_Esmtp_Auth_NTLMAuthenticator->getDomainAndUsername('prhc.systeembeh...')
#2 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php(66): Swift_Transport_Esmtp_Auth_NTLMAuthenticator->sendMessage3('NTLMSSP????????...', 'prhc.systeembeh...', '', '?A(?Hu??', ':????n??', Object(Swift_SmtpTransport))
#3 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php(176): Swift_Transport_Esmtp_Auth_NTLMAuthenticator->authenticate(Object(Swift_SmtpTransport), 'prhc.systeembeh...', '')
#4 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(307): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport))
#5 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(118): Swift_Transport_EsmtpTransport->_doHeloCommand()
#6 /var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start()
#7 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(329): Swift_Mailer->send(Object(Swift_Message), Array)
#8 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(151): Illuminate\Mail\Mailer->sendSwiftMessage(Object(Swift_Message))
#9 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(214): Illuminate\Mail\Mailer->send('emails.checkin-...', Array, Object(Closure))
#10 /var/www/snipeit/app/controllers/admin/AssetsController.php(660): Illuminate\Support\Facades\Facade::__callStatic('send', Array)
#11 /var/www/snipeit/app/controllers/admin/AssetsController.php(660): Illuminate\Support\Facades\Mail::send('emails.checkin-...', Array, Object(Closure))
#12 [internal function]: Controllers\Admin\AssetsController->postCheckin('1070')
#13 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): call_user_func_array(Array, Array)
#14 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('postCheckin', Array)
#15 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(62): Illuminate\Routing\ControllerDispatcher->call(Object(Controllers\Admin\AssetsController), Object(Illuminate\Routing\Route), 'postCheckin')
#16 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Routing/Router.php(967): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'Controllers\Adm...', 'postCheckin')
#17 [internal function]: Illuminate\Routing\Router->Illuminate\Routing{closure}('1070')
#18 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Routing/Route.php(109): call_user_func_array(Object(Closure), Array)
#19 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1033): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#20 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1001): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#21 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(775): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#22 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(745): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#23 /var/www/snipeit/vendor/barryvdh/laravel-debugbar/src/Middleware/Stack.php(34): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#24 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Barryvdh\Debugbar\Middleware\Stack->handle(Object(Illuminate\Http\Request), 1, true)
#25 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#26 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#27 /var/www/snipeit/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#28 /var/www/snipeit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(641): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#29 /var/www/snipeit/public/index.php(49): Illuminate\Foundation\Application->run()
#30 {main} [] []

@snipe
Copy link
Owner

snipe commented Mar 3, 2016

Does it happen ever time you try to send mail? What are you doing to trigger it?

@IxFail
Copy link
Author

IxFail commented Mar 3, 2016

Yes it is happing every time Try to send a mail.

I activate that users get a mail when an asset is checked in or out of their name. When I check an asset in or out I get the 500 error in about 6 seconds.

@snipe
Copy link
Owner

snipe commented Mar 3, 2016

Do all of your users have email addresses in your system?

@IxFail
Copy link
Author

IxFail commented Mar 3, 2016

Yes all users have an email adress.

@snipe
Copy link
Owner

snipe commented Mar 3, 2016

It looks like it's trying to use prhc.systeembeh somewhere. Is that a username, a user's email address, or what?

@IxFail
Copy link
Author

IxFail commented Mar 3, 2016

prhc.systeembeh should be prhc.systeembeheer as prhc.systeembeheer is in the mail.php as the username for smtp.
Could the problem be caused by the . Between prhc and systeembeheer?

@snipe
Copy link
Owner

snipe commented Mar 3, 2016

I think it's the no password thing that's causing the problem. See this bit in the stack trace:

/var/www/snipeit/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php(176): Swift_Transport_Esmtp_Auth_NTLMAuthenticator->authenticate(Object(Swift_SmtpTransport), 'prhc.systeembeh...', '')

@IxFail
Copy link
Author

IxFail commented Mar 3, 2016

Tomorrow I will enter my own mail credentials(which requires a password) because the prhc.systeembeheer does not has a password. And I will check if the error still pops-up

@IxFail
Copy link
Author

IxFail commented Mar 4, 2016

Okay the Undefined offset: 1 error was indeed caused by the empty password field, I created a special service account that is allowed to send from the mailbox and Tadaa. I can send mails with Snipe-IT.

Thank you for your help @snipe

@snipe snipe closed this as completed Mar 22, 2016
@hoaimv
Copy link

hoaimv commented Jan 7, 2021

Dear snipe ,IxFail
Thanks to your support in this case, you can guide in more detail what to fix to be able to fix this error.
I have the same situation as you
How do I fix it with the code below
_Transport_SmtpAgent $agent to read/write
*/
public function afterEhlo(Swift_Transport_SmtpAgent $agent)
{
if ($this->username) {
$count = 0;
$errors = [];
foreach ($this->getAuthenticatorsForAgent() as $authenticator) {
if (in_array(strtolower($authenticator->getAuthKeyword()), array_map('strtolower', $this->esmtpParams))) {
++$count;
try {
if ($authenticator->authenticate($agent, $this->username, $this->password)) {
return;
}
} catch (Swift_TransportException $e) {
// keep the error message, but tries the other authenticators
$errors[] = [$authenticator->getAuthKeyword(), $e->getMessage()];
}
}
}

        $message = 'Failed to authenticate on SMTP server with username "'.$this->username.'" using '.$count.' possible authenticators.';
        foreach ($errors as $error) {
            $message .= ' Authenticator '.$error[0].' returned '.$error[1].'.';
        }
        throw new Swift_TransportException($message);
    }
}

/**
 * Not used.
 */
public function getMailParams()
{
    return [];
}

/**
 * Not used.
 */
public function getRcptParams()
{
    return [];
}

/**

Thanks you so much

@IxFail
Copy link
Author

IxFail commented Jan 8, 2021

Hi @hoaimv ,

This issue was solved 4 years ago, so my memory is a little rusty, but if I read my own replies; I just added a SMTP account that was using a password.
'username' => 'PUT HERE A SMTP USERNAME',

'password' => 'PUT HERE THE USER PASSWORD FOR SMPT',

In Snipe version 2.1.0-41 the password was mandatory even if the SMTP user could send mail without a password.

@hoaimv
Copy link

hoaimv commented Jan 13, 2021

Hi @hoaimv ,

This issue was solved 4 years ago, so my memory is a little rusty, but if I read my own replies; I just added a SMTP account that was using a password.
'username' => 'PUT HERE A SMTP USERNAME',

'password' => 'PUT HERE THE USER PASSWORD FOR SMPT',

In Snipe version 2.1.0-41 the password was mandatory even if the SMTP user could send mail without a password.

Dear IxFail
Can you please send me 2 files mail.php config & AuthHandler.php has successfully run help
Thank You so much

@IxFail
Copy link
Author

IxFail commented Jan 13, 2021

@hoaimv,

Sorry I cant do that, I don't work for the company that used Snipe-IT anymore +I haven't used Snipe-It for atleast 3 years.

I wish you the best in finding a solution with your problem.

@hoaimv
Copy link

hoaimv commented Jan 27, 2021

Dear snipe ,IxFail
when using snipe it when checking in and check out only send emails that have 2 layers security opened
Mail with 2-layer security off does not receive mail
Thanks to your support

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

No branches or pull requests

3 participants