Send telnet email from .bat

powerswitch 41 Reputation points
2021-06-30T12:30:34.987+00:00

Hi dear colleagues,

i try to send an email from cmd but i would like to script in a bat file:

telnet mail.internal.ent.com 25
mail from:test.@ent.com
RCPT TO:me@ent.com
data
Subject:Test
.

but i dont know how, so please could anybody help me?

Thanks in advance and BR!!!

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,407 questions
0 comments No comments
{count} votes

3 additional answers

Sort by: Most helpful
  1. Castorix31 81,341 Reputation points
    2021-06-30T12:56:47.047+00:00

    You can use a PowerShell script
    How to Send an Email Using Windows PowerShell
    or a VBS script
    Add Send Email to any VBscript

    1 person found this answer helpful.
    0 comments No comments

  2. Sam of Simple Samples 5,516 Reputation points
    2021-06-30T18:12:53.79+00:00

    After executing telnet, input is read by telnet, not by the command prompt. So in other words the commands you show after telnet would not be read from the bat file. So try putting the following in a separate file (for example mail.txt):

    mail from:test.@ent.com
    RCPT TO:me@ent.com
    data
    Subject:Test
    .
    

    Be sure to put a quit command at the end. Then execute the following:

    telnet mail.internal.ent.com 25<mail.txt
    

    Except mail.txt would be the entire path and filename; you might need to use double quotes around the path and filename.

    I consider that to be a cumbersome way to do it. I suggest using something else, as in the answer from Castorix31. But if you must use a command prompt then the preceding should work.

    1 person found this answer helpful.
    0 comments No comments

  3. powerswitch 41 Reputation points
    2021-07-01T07:36:46.257+00:00

    Thanks to all for your answers and BR!!!!!

    0 comments No comments