Send email from gmail using Telnet

2019-02-25 10:58发布

问题:

I am working on windows and I have enabled telnet client

In cmd prompt:

$telnet smtp.gmail.com 587
220 mx.google.com ESMTP dk3sm50678627pbc.32 - gsmtp
$Helo
250 mx.google.com at your service
$ mail from: <myuser@gmail.com>
530 5.7.0 Must issue a STARTTLS command first. dk3sm50678627pbc.32 - gsmtp
$ STARTTLS
220 2.0.0 Ready to start TLS
$ mail from:
C:\Users\{myuser}>
Connection to host lost.

Don't know What is the problem ?

Can anyone help me out , how i can send emails from gmail server using telnet from command line >

回答1:

smtp.gmail.com requires TLS. The basic telnet client that comes with windows does not know how to negotiate TLS with a server. You may want to use openssl instead, which is able to negotiate TLS. See http://www.madboa.com/geek/openssl/#cs-smtp for an example of how to do this.



回答2:

Put into a VBS file, ie sendmail.vbs.

Set emailObj      = CreateObject("CDO.Message")
emailObj.From     = "cat@gmail.com"

emailObj.To       = "cat@gmail.com"

emailObj.Subject  = "Test CDO"
emailObj.TextBody = "Test CDO"

emailObj.AddAttachment "c:\windows\win.ini"

Set emailConfig = emailObj.Configuration

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")    = 2  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")      = true 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")    = "cat"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")    = "Ccat1"
emailConfig.Fields.Update

emailObj.Send

If err.number = 0 then Msgbox "Done"

At Google's web site for GMail you have to turn this feature on for CDO to work.

At your Gmail page click Settings - Accounts and Import - Other Google Account Settings - [At very bottom of page] Allow less secure apps.

Also from memory you also have to click a link in an email the first time you use it (it's been a few years).



回答3:

The gmail smtp must use smtp auth before you sending your email. The smtp auth need username and password.

see this link blow if you can read in Chinese. http://linxucn.blog.51cto.com/1360306/837365

Last I sugguest you use java to ask gmail smtp server to send email, It will be more easy , becasue you needn't encode the smtp auth to BASE64 or anything else.

GOGOGO, good luck :)