我正在嘗試寫一個腳本通過gmail發送郵件。
我可以連接到Gmail,但是當我嘗試去遮蓋它時會失敗。
任何指針握手握手?Gmail TLS hackshake haskell失敗
下面是代碼:
import Network.Socket
import Network
import Network.TLS
import Network.TLS.Extra
import Crypto.Random
import Data.CertificateStore -- to remove
import System.Certificate.X509 --to use I think
import System.IO
import Text.Printf
import Control.Monad (forever)
import qualified Data.ByteString.Char8 as B
main :: IO()
main = emailGmail2
tListen :: Context -> IO()
tListen ctx =
forever $ recvData ctx >>= B.putStrLn
cWrite :: Handle -> String -> IO()
cWrite h s = do
hPrintf h "%s\r\n" s
printf "> %s\n" s
cListen :: Handle -> IO()
cListen h =
forever $ hGetLine h >>= putStrLn
emailGmail2 = do
let
host = "smtp.gmail.com"
port = 587
params = defaultParamsClient
g <- newGenIO :: IO SystemRandom
h <- connectTo host (PortNumber (fromIntegral port))
hSetBuffering h LineBuffering
cWrite h "EHLO"
cWrite h "STARTTLS"
--cListen h
con <- contextNewOnHandle h params g
handshake con
tListen con
而這裏的錯誤:
HandshakeFailed (Error_Packet_Parsing "Failed reading: invalid header type: 50\nFrom:\theader\n\n")
哇!歡迎來到SO,開門見山。 –
謝謝,我看了一下RF,但沒有發現錯誤。我會嘗試從它裏面創建一個lib(我有技能嗎?),因爲這是默認情況下應該存在的東西(我的觀點)。 – Sarfraz