Send mail via CMD console

前端 未结 4 1911
夕颜
夕颜 2021-02-05 14:56

Hi i want to send mail via microsoft cmd console. I tried many way, but i didnt succeed.

i tried this article http://jpsoft.com/help/index.htm?sendmail.htm

<         


        
相关标签:
4条回答
  • 2021-02-05 15:48

    Scenario: Your domain: mydomain.com Domain you wish to send to: theirdomain.com

    1. Determine the mail server you're sending to. Open a CMD prompt Type

    NSLOOKUP 
     set q=mx 
     theirdomain.com
    

    Response:

    Non-authoritative answer: 
    theirdomain.com MX preference = 50, mail exchanger = mail.theirdomain.com 
    Nslookup_big
    

    EDIT Be sure to type exit to terminate NSLOOKUP.

    2. Connect to their mail server

    SMTP communicates over port 25. We will now try to use TELNET to connect to their mail server "mail.theirdomain.com"

    Open a CMD prompt

    TELNET MAIL.THEIRDOMAIN.COM 25
    

    You should see something like this as a response:

    220 mx.google.com ESMTP 6si6253627yxg.6
    

    Be aware that different servers will come up with different greetings but you should get SOMETHING. If nothing comes up at this point there are 2 possible problems. Port 25 is being blocked at your firewall, or their server is not responding. Try a different domain, if that works then it's not you.

    3. Send an Email

    Now, use simple SMTP commands to send a test email. This is very important, you CANNOT use the backspace key, it will work onscreen but not be interpreted correctly. You have to type these commands perfectly.

    ehlo mydomain.com 
    mail from:<martin9700@mydomain.com> 
    rcpt to:<recipient@theirdomain.com> 
    data 
    This is a test, please do not respond
    . 
    quit
    

    So, what does that all mean? EHLO - introduce yourself to the mail server HELO can also be used but EHLO tells the server to use the extended command set (not that we're using that).

    MAIL FROM - who's sending the email. Make sure to place this is the greater than/less than brackets as many email servers will require this (Postini).

    RCPT TO - who you're sending it to. Again you need to use the brackets. See Step #4 on how to test relaying mail!

    DATA - tells the SMTP server that what follows is the body of your email. Make sure to hit "Enter" at the end.

    . - the period alone on the line tells the SMTP server you're all done with the data portion and it's clear to send the email.

    quit - exits the TELNET session.

    4. Test SMTP relay Testing SMTP relay is very easy, and simply requires a small change to the above commands. See below:

    ehlo mydomain.com 
    mail from:<martin9700@mydomain.com> 
    rcpt to:<recipient@someotherdomain.com> 
    data 
    This is a test, please do not respond 
    . 
    quit
    

    See the difference? On the RCPT TO line, we're sending to a domain that is not controlled by the SMTP server we're sending to. You will get an immediate error is SMTP relay is turned off. If you're able to continue and send an email, then relay is allowed by that server.

    0 讨论(0)
  • 2021-02-05 15:50

    A couple more command-line mailer programs:

    • mailsend
    • Mail Alert Simple Mailer

    Both support SSL too.

    0 讨论(0)
  • 2021-02-05 15:52

    Unless you want to talk to an SMTP server directly via telnet you'd use commandline mailers like blat:

    blat -to you@example.com -f me@example.net -s "mail subject" ^
      -server smtp.example.net -body "message text"
    

    or bmail:

    bmail -s smtp.example.net -t you@example.com -f me@example.net -h ^
      -a "mail subject" -b "message text"
    

    You could also write your own mailer in VBScript or PowerShell.

    0 讨论(0)
  • 2021-02-05 15:56

    From Linux you can use 'swaks' which is available as an official packages on many distros including Debian/Ubuntu and Redhat/CentOS on EPEL:

    swaks -f you@example.net -t someone@example.com \
        --server mail.example.com
    
    0 讨论(0)
提交回复
热议问题