2

This very same problem already has some similar entries in stackoverflow, but none of them ever had any answers/solutions apart from some more basic coding hints.

I am using Symfony2 framework+swiftmailer on an OVH shared server and when sending a mail through the user interface (of the web page) I am getting intermittently the http error: Expected response code 250 but got code "", with message "".

With some googling for this error I understand that the server receives an order to read a mail, which is empty, so that it does not know what to do with an empty mail (no to, no from, no body, ...NULL in a way).

I am not sending mass mail, only one after one. The intermittent character of this makes debugging awkward as anytime you make a little tweak and it seems to work, you can not not be sure if the last tweak fixed it or if "it" simply decided to "wake up" again. So far all my little counter tweaks ended up that the empty smtp return from the server popped up again after some hours/some days. Because of this I am still hiding the site behind a htaccess so that traffic is extremely small (it is basically only myself). Intermittence is around 5 to 10% of all mails. If that empty error appears then for 95% of any tweak in the code the error remains. There is only one "tweak" which so far made the error go away "reliably": reloading the parameter.yml, but since there is 5% of cases where I tweaked something else and the error also went away I can't be sure if I should concentrate on the parameters. But again, the error will come back after hours/days in any case. The whole looks more like a server-cache/CDM issue.

Here's the details of code to be known (since it is working "most of times", the code as such is probably clean.. but one never knows).

parameters.yml:

mailer_transport: smtp
mailer_host: ssl0.ovh.net
mailer_port: 465 
# OR alternatively (gives the same result) :
#    mailer_host: ns0.ovh.net
#    mailer_port: 587
mailer_user: *********
mailer_password: **********

config.yml:

transport: "%mailer_transport%"
host:      "%mailer_host%"
username:  "%mailer_user%"
password:  "%mailer_password%"
port:      "%mailer_port%"

# and also :
fos_user :
    from_email:       
        address:      ********* (same as mailer_user)
        sender_name:  ***********

controllerXYZ:

$mailer=$this->get('mailer');
$params=$form->getData();
$subject=$params['subject'];
$body=$params['body'];
$userManager=$this->get('fos_user.user_manager');
$toUser=$userManager->findUserBy(array('username'=>$comment->getAuthor()));
$to=$toUser->getEmail();
$from=$this->getUser()->getEmail();

$message= \Swift_Message::newinstance()
->setSubject($subject)
->setBody($body)
->setFrom($from)
->setTo($to);

$mailer->send($message);

I "tweaked" with sleep(x), with \vendor\SM\SM\lib\classes\Swift\Transport, file=EsmtpTransport.php timeout, some try/catches, ports/server id's, spool but always got the error back after a while. All the tweaks are set back to "standard" of course.

I could try another mailer (phpmail), but since it seems OVH/CDM/server related I am worried to get the same thing again.

Alternatively I could also try to make the error appear "on purpose" to get a hint; but I could not even get that done.

GIVE ME PLEASE A DIRECTION TO TRY OUT!

4

3 回答 3

1

三个多月以来,我没有找到间歇性问题的原因。因此,我实施了一项工作。虽然我不是很满意,但它让我可以公开网站。

这是尝试和捕获的解决方法,丑陋但从 1 个月开始工作(使用 Symphony2 类):

$message= \Swift_Message::newinstance()
    ->setSubject($subject)
    ->setBody($body)
    ->setFrom($from)
    ->setTo($to);

try
    {
        try
            {
                $mailer->send($message,$failure);
                $translatedText1 = $this->get('translator')->trans('flash.mail.sent1');
                $translatedText2 = $this->get('translator')->trans('flash.mail.sent2');
                $messageOut=$translatedText1.$mailarticle->getAuthor().$translatedText2;
            }
        catch(\Exception $e)
           {
                mail($to,$subject,$body,'From: '.$from);
                $translatedText1 = $this->get('translator')->trans('flash.mail.std1');
                $translatedText2 = $this->get('translator')->trans('flash.mail.std2');
                $messageOut=$translatedText1.$mailarticle->getAuthor().$translatedText2;
           }                                    
    }
catch(\Exception $e)
        {
             $translatedText1 = $this->get('translator')->trans('flash.mail.except1');
             $translatedText2 = $this->get('translator')->trans('flash.mail.except2');
             $messageOut=$translatedText1.$e->getMessage().$translatedText2.$failure;
        }

$translatedText1/2 和 $messageout 部分只是发送邮件后显示给用户的消息文本。object->trans() 是 Symfony 的一个文本功能。

奇怪的是,尽管我没有收到一个答案,但这个问题却获得了一些积分。尽管如此,由于上述解决方案并没有解决根本原因 - 任何解决原因的人仍然会非常感激!

于 2015-01-03T13:08:53.807 回答
0

这是我使用共享电子邮件 config.yml 的 OVH 计划(值当然是参数,复制到此处以获得更多可见性):

# Swiftmailer Configuration
swiftmailer:
    transport: mail
    auth_mode: login
    host:      ssl0.ovh.net
    port:      587
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

我之前尝试过的其他传输方式:sendmail、smtp。奇怪的是:一旦我将传输配置设置为mail,我注意到 Symfony 在使用所选的 Swift_Transport 实现之前存在延迟。我可以说我处于开发模式吗?

所以,我的建议是:设置配置,去喝杯咖啡,享受吧。

于 2016-06-28T18:38:41.497 回答
0

我遇到了同样的问题,ovh 支持告诉我无法将 smtp 与共享服务器一起使用。解决方案是使用transport: sendmailtransport: mail用于旧版本的 swiftmailer(现已弃用)

于 2020-08-05T19:23:58.857 回答