(Ruby) Getting Net::SMTP working with Gmail…?

后端 未结 5 1272
野的像风
野的像风 2020-12-05 17:50

Does anyone have any quality (and up-to-date) information regarding sending mail via Gmail using Ruby\'s Net::SMTP? I\'ve seen several examples -- most dating from 2007 to

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 18:46

    Are you connecting to smtp.gmail.com port 465 I am assuming? .

    openssl s_client -connect smtp.gmail.com:587
    

    CONNECTED(00000003) 8298:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:601:

    The error looks very similar to yours. The following command does work:

     openssl s_client  -starttls smtp -connect smtp.gmail.com:587
    

    So I think what is happening is that you do not have STARTTLS support enabled. I am not sure how to do it in ruby buy what I did find out is that the action_mailer_tls plugin allows this by patching Net::SMTP. As of Ruby 1.8.7, Net::SMTP has this support built-in.

    If you are using Ruby < 1.8.7 here is the patch.

提交回复
热议问题