I'm not familar with the INDY SMTP component. I want to send a mail with INDY and Office 365. Here is a nice topic which helped me a lot: What do the SMTP Indy component security and authentication properties do? But I did not figured out how to use SASL. Office365 adress is smtp.office365.com with port 587 and TLS. So I added an SMTP and an OpenSSL-IOHandler to my form and setted the properties. But I didn't work, the app is just freezing. I need to know how to use SASL with Office365.
Thanks.
Additionally, by using this method, your IP address doesn’t need to be static like it would with the relay server method! Once you log in to the Outlook mail app, use the toolbar and navigate to Settings > Mail > POP and IMAP. Then, click on More Settings > Outgoing Server to set up your SMTP settings. Server: smtp.office365.com
SMTP client submission (Option 1) is not compatible with your business needs or with your device SMTP relay lets Office 365 relay emails on your behalf by using a connector that's configured with your public IP address or TLS a certificate. Setting up a connector makes this a more complicated option.
SMTP relay lets Office 365 relay emails on your behalf by using a connector that's configured with your public IP address or TLS a certificate. Setting up a connector makes this a more complicated option.
·Type open smtp.office365.com 587 (25). ·If you connected successfully to an Office 365 server, you will receive a response line similar to below: 220 BY1PR10CA0041.outlook.office365.com Microsoft ESMTP MAIL Service ready at Mon, 1 Jun 2015 12:00:00 +0000
Office365 only supports the LOGIN
SASL on TLS port 587.
The following code works fine for me when I just tried it (all of these settings can also be set up at design-time as well):
setting the TIdSMTP.AuthType
property to satDefault
, which uses the SMTP AUTH LOGIN
command:
var
idSMTP1: TIdSMTP;
begin
idSMTP1 := TIdSMTP.Create(nil);
try
idSMTP1.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(idSMTP1);
idSMTP1.UseTLS := utUseExplicitTLS;
TIdSSLIOHandlerSocketOpenSSL(idSMTP1.IOHandler).SSLOptions.Method := sslvSSLv3;
idSMTP1.Host := 'smtp.office365.com';
idSMTP1.Port := 587;
idSMTP1.AuthType := satDefault;
idSMTP1.Username := ...;
idSMTP1.Password := ...;
try
idSMTP1.Connect;
try
idSMTP1.Authenticate;
finally
idSMTP1.Disconnect;
end;
ShowMessage('OK');
except
on E: Exception do
begin
ShowMessage(Format('Failed!'#13'[%s] %s', [E.ClassName, E.Message]));
raise;
end;
end;
finally
idSMTP1.Free;
end;
setting the TIdSMTP.AuthType
property to satSASL
and using TIdSASLLogin
, which uses the same SMTP AUTH LOGIN
command:
var
idSMTP1: TIdSMTP;
idSASLLogin: TIdSASLLogin;
idUserPassProvider: TIdUserPassProvider;
begin
idSMTP1 := TIdSMTP.Create(nil);
try
idSMTP1.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(idSMTP1);
idSMTP1.UseTLS := utUseExplicitTLS;
TIdSSLIOHandlerSocketOpenSSL(idSMTP1.IOHandler).SSLOptions.Method := sslvSSLv3;
idSMTP1.Host := 'smtp.office365.com';
idSMTP1.Port := 587;
idSASLLogin := TIdSASLLogin.Create(idSMTP1);
idUserPassProvider := TIdUserPassProvider.Create(idSASLLogin);
idSASLLogin.UserPassProvider := idUserPassProvider;
idUserPassProvider.Username := ...;
idUserPassProvider.Password := ...;
idSMTP1.AuthType := satSASL;
idSMTP1.SASLMechanisms.Add.SASL := idSASLLogin;
try
idSMTP1.Connect;
try
idSMTP1.Authenticate;
finally
idSMTP1.Disconnect;
end;
ShowMessage('OK');
except
on E: Exception do
begin
ShowMessage(Format('Failed!'#13'[%s] %s', [E.ClassName, E.Message]));
raise;
end;
end;
finally
idSMTP1.Free;
end;
Update: Office365 no longer supports SSL v3, you must use TLS v1.x now:
(idSMTP1.IOHandler).SSLOptions.Method := sslvTLSv1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With