Skip to content

Instantly share code, notes, and snippets.

@yskszk63
Created January 24, 2020 11:14
Show Gist options
  • Save yskszk63/9337fa50ac51829e8c155874762a2f3e to your computer and use it in GitHub Desktop.
Save yskszk63/9337fa50ac51829e8c155874762a2f3e to your computer and use it in GitHub Desktop.
Hello StartTLS
220 SG ESMTP service ready at ismtpd0008p1hnd1.sendgrid.net
[EHLO]
250-smtp.sendgrid.net
250-8BITMIME
250-PIPELINING
250-SIZE 31457280
250-STARTTLS
250-AUTH PLAIN LOGIN
250 AUTH=PLAIN LOGIN
[STARTTLS]
220 Begin TLS negotiation now
[Upgrade socket]
[EHLO (tls)]
250-smtp.sendgrid.net
250-8BITMIME
250-PIPELINING
250-SIZE 31457280
250-STARTTLS
250-AUTH PLAIN LOGIN
250 AUTH=PLAIN LOGIN
[QUIT (tls)]
221 See you later
$sock = [Net.Sockets.TcpClient]::new('smtp.sendgrid.net', 587)
$tx = [Io.StreamWriter]::new($sock.GetStream())
$rx = [Io.StreamReader]::new($sock.GetStream())
$tx.AutoFlush = $true
$rx.ReadLine()
""
"[EHLO]"
$tx.WriteLine('EHLO smtp.sendgrid.net')
do {
$r = $rx.ReadLine()
$r
} while ($r[3] -eq '-')
""
"[STARTTLS]"
$tx.WriteLine('STARTTLS')
$rx.ReadLine()
""
"[Upgrade socket]"
$ssl = [Net.Security.SslStream]::new($sock.GetStream(), $false, $null, $null)
$ssl.AuthenticateAsClient('smtp.sendgrid.net')
$tx = [Io.StreamWriter]::new($ssl)
$rx = [Io.StreamReader]::new($ssl)
$tx.AutoFlush = $true
""
"[EHLO (tls)]"
$tx.WriteLine('EHLO smtp.sendgrid.net')
do {
$r = $rx.ReadLine()
$r
} while ($r[3] -eq '-')
""
"[QUIT (tls)]"
$tx.WriteLine('QUIT')
$rx.ReadLine()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment