如何使用简单的SMTP命令通过Gmail发送电子邮件? [英] How to send email using simple SMTP commands via Gmail?

查看:541
本文介绍了如何使用简单的SMTP命令通过Gmail发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于教育目的,我需要通过SMTP服务器发送电子邮件,使用SMTP的基本规则和简单规则。



我可以使用。但是我无法使用TLS并使用命令行验证Gmail的SMTP服务器(或以编程语言发送命令)。任何人都可以帮助?

解决方案

发送gmail,您需要使用加密连接。单独使用telnet是不可能的,但您可以使用 openssl 等工具



使用openssl中的starttls选项连接,将普通连接转换为加密...



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



直接连接到ssl sockect .. 。



openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof



EHLO本地主机



之后,使用base64编码的用户名/密码对服务器进行身份验证



AUTH PLAIN AG15ZW1haWxAZ21haWwuY29tAG15cGFzc3dvcmQ =



从命令行中获取:

  perl -MMIME :: Base64 -e'print encode_base64(\000myemail\@gmail.com\000mypassword)'
AG15ZW1haWxAZ21haWwuY29tAG15cGFzc3dvcmQ =

然后继续执行mail from:,就像您的示例



示例会话:

  openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof 
[...很多openssl输出...]
220 mx.google.com ESMTP m46sm11546481eeh.9
EHLO本地主机
250-mx.google.com在您的服务, [1.2.3.4]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH
250 ENHANCEDSTATUSCODES
AUTH PLAIN AG5pY2UudHJ5QGdtYWlsLmNvbQBub2l0c25vdG15cGFzc3dvcmQ =
235 2.7 .0接受
MAIL FROM:< gryphius-demo@gmail.com>
250 2.1.0 OK m46sm11546481eeh.9
rcpt to:< somepoorguy@example.com&
250 2.1.5 OK m46sm11546481eeh.9
数据
354前进m46sm11546481eeh.9
主题:它工作

yay!

250 2.0.0 OK 1339757532 m46sm11546481eeh.9
退出
221 2.0.0关闭连接m46sm11546481eeh.9
读取:errno = 0


For educational purposes, I need to send an email through an SMTP server, using SMTP's fundamental and simple rules.

I was able to do that using smtp4dev. I telnet localhost 25 and and commands are:

I want to do the same thing, using Gmail SMTP server. However, it requires authentication and TLS. I can't figure out how to do that for Gmail. Here's a screenshot of telnet smtp.gmail.com 587:

I searched and found many links including Wikipedia's article about STARTTLS command. But I'm not able to use TLS and authenticate to Gmail's SMTP server using command line (or sending commands myself in programming languages). Can anyone help?

解决方案

to send over gmail, you need to use an encrypted connection. this is not possible with telnet alone, but you can use tools like openssl

either connect using the starttls option in openssl to convert the plain connection to encrypted...

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

or connect to a ssl sockect directly...

openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof

EHLO localhost

after that, authenticate to the server using the base64 encoded username/password

AUTH PLAIN AG15ZW1haWxAZ21haWwuY29tAG15cGFzc3dvcmQ=

to get this from the commandline:

perl -MMIME::Base64 -e 'print encode_base64("\000myemail\@gmail.com\000mypassword")' 
AG15ZW1haWxAZ21haWwuY29tAG15cGFzc3dvcmQ=

then continue with "mail from:" like in your example

example session:

openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof
[... lots of openssl output ...]
220 mx.google.com ESMTP m46sm11546481eeh.9
EHLO localhost
250-mx.google.com at your service, [1.2.3.4]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH
250 ENHANCEDSTATUSCODES
AUTH PLAIN AG5pY2UudHJ5QGdtYWlsLmNvbQBub2l0c25vdG15cGFzc3dvcmQ=
235 2.7.0 Accepted
MAIL FROM: <gryphius-demo@gmail.com>
250 2.1.0 OK m46sm11546481eeh.9
rcpt to: <somepoorguy@example.com>
250 2.1.5 OK m46sm11546481eeh.9
DATA
354  Go ahead m46sm11546481eeh.9
Subject: it works

yay!
.
250 2.0.0 OK 1339757532 m46sm11546481eeh.9
quit
221 2.0.0 closing connection m46sm11546481eeh.9
read:errno=0

这篇关于如何使用简单的SMTP命令通过Gmail发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆