nickosl50 Posted November 27, 2017 Share Posted November 27, 2017 Hi, I made a simple Unigui app to send email to a recipient using my gmail account. While the Message subject appears correctly in Greek , the message body displays Greek char like ????. I use TIdSMP, TIdMessage and TIdSSLIOHandlerSocketOpenSSL. The code that sends email is the following: procedure Gmail(username, password, totarget, subject, body: string); var DATA: TIdMessage; SMTP: TIdSMTP; SSL: TIdSSLIOHandlerSocketOpenSSL; ErrorSendMail : string; begin SMTP := TIdSMTP.Create(nil); DATA := TIdMessage.Create(nil); SSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil); SSL.SSLOptions.Method := sslvTLSv1; SSL.SSLOptions.Mode := sslmUnassigned; SSL.SSLOptions.VerifyMode := []; SSL.SSLOptions.VerifyDepth := 0; DATA.CharSet := 'ISO-8859-7'; DATA.From.Address := username; DATA.Recipients.EMailAddresses := totarget; DATA.subject := subject; DATA.body.text := UTF8Encode(body); DATA.ContentType := 'text/html'; SMTP.IOHandler := SSL; SMTP.Host := 'smtp.gmail.com'; SMTP.Port := 587; SMTP.username := username; SMTP.password := password; SMTP.UseTLS := utUseExplicitTLS; try try SMTP.Connect; SMTP.Send(DATA) ; except on E:Exception do ErrorSendMail := '' + E.Message end; finally if SMTP.Connected then begin SMTP.Disconnect; SMTP.Free; DATA.Free; SSL.Free; end; end; end; I would appreciate if someone could give me a clue about the problem. Thank you very much Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted November 28, 2017 Share Posted November 28, 2017 ... DATA.CharSet := 'ISO-8859-7'; ... DATA.body.text := UTF8Encode(body); ... 2 different encodings?! Quote Link to comment Share on other sites More sharing options...
nickosl50 Posted November 28, 2017 Author Share Posted November 28, 2017 2 different encodings?! Even with the same encoding (either both ISO-8859-7 or both UTF-8) the problem is the same. Mail subject appears correctly but body does not. Quote Link to comment Share on other sites More sharing options...
nickosl50 Posted November 29, 2017 Author Share Posted November 29, 2017 The only problem was that I had to place contexttype setting before charset setting DATA.ContentType := 'text/html'; DATA.CharSet := 'UTF-8'; No need to encode the body of the message Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.