dongyang5716 2015-12-03 09:49
浏览 262

使用套接字和STMP TLS的意外服务器响应

This is my first time I do anything with SMTP, so please have patience if I am doing something terribly wrong here :) Normally, I just use PHPMailer, but this is not an option in this case.

I am trying to send an email to people in a mailing list. I am using fsockopen and I need to use a TLS connection to do this.

This is what I do:

  • $conn = fsockopen() // my details goes in there, it connects.
  • HELO myhost.com (fwrite)
  • STARTTLS (fwrite)
  • stream_socket_enable_crypto( $conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT );
  • HELO myhost.com (fwrite)
  • AUTH LOGIN (fwrite)
  • base64_encoded USERNAME (fwrite)
  • base64_encoded PASSWORD (fwrite)
  • MAIL FROM: (fwrite)
  • RCPT TO:; (fwrite)
  • DATA (fwrite)
  • A string with all my headers (fwrite)
  • fclose($conn);

This is where something goes wrong

After using an encypted connection I can't seem to successfully read the server response. For example, when trying to read the response by using fgets($conn,1024) after my authentication it takes forever and then finally I will get a highly encrypted code not being able to look for response "235" (to make sure my authentication succeeded).

And then when I write MAIL FROM my response will look like this:

.0.0 SMTP server ready

While I think I would want something like this:

250 2.0.0

Something gets wrong, but I don't know why. I hope any of all you experts out there can help me go to the bottom with this problem :)

Thanks in advance!

SOLVED IT

In case anyone else runs into this problem.

This order works

  • $conn = fsockopen() // my details goes in there, it connects.
  • EHLO myhost.com (fwrite)
  • STARTTLS (fwrite)
  • stream_socket_enable_crypto( $conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT );
  • EHLO myhost.com (fwrite)
  • AUTH LOGIN (fwrite)
  • base64_encoded USERNAME (fwrite)
  • base64_encoded PASSWORD (fwrite)
  • MAIL FROM: (fwrite)
  • RCPT TO:; (fwrite)
  • DATA (fwrite)
  • A string with all my headers (fwrite)
  • fclose($conn);

Between every call I added the following:

stream_set_timeout($conn, 300);
set_time_limit(310);

Suddenly I got the expected replies from the server and the mail was successfully sent.

  • 写回答

1条回答 默认 最新

  • dongxu4023 2017-07-24 10:01
    关注

    SOLVED IT

    In case anyone else runs into this problem.

    This order works

    • $conn = fsockopen() // my details goes in there, it connects.
    • EHLO myhost.com (fwrite)
    • STARTTLS (fwrite)
    • stream_socket_enable_crypto( $conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT );
    • EHLO myhost.com (fwrite)
    • AUTH LOGIN (fwrite)
    • base64_encoded USERNAME (fwrite)
    • base64_encoded PASSWORD (fwrite)
    • MAIL FROM: (fwrite)
    • RCPT TO:; (fwrite)
    • DATA (fwrite)
    • A string with all my headers (fwrite)
    • fclose($conn);

    Between every call I added the following:

    stream_set_timeout($conn, 300);
    set_time_limit(310);
    

    Suddenly I got the expected replies from the server and the mail was successfully sent.

    – entiendoNull

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog