I use MailKit library to send mail from ASP.NET Core application. I also tried to avoid MailKit library and use TcpClient directly to send commands to SMTP server (to ensure that library is not a problem). Postfix SMTP server is located on Linux Ubuntu 18.04 server where web application is also being hosted.
When I test application locally (on Windows machine) MailKit successfully authenticates and E-mail is being sent. However, when I run application on Linux Ubuntu authentication fails (same server, port, username and password). When I examine log of communication with the server, problem is obvious - when app is being run on Linux server, application sends root user as username to the SMTP server. I have not specified that as username to be send.
Is there any automatic rule for Postfix to authenticate users? Is there need for any additional Postfix configuration?
(I've changed original usernames and passwords).
Windows Server ...
C: AUTH LOGIN
S: 334 VXNlcm5hbWU6
C: dGVzdEB0ZXN0LmNvbQ==
S: 334 UGFzc3dvcmQ6
C: dGVzdHBhc3N3b3JkCg==
S: 235 2.7.0 Authentication successful
Linux Ubuntu Server ...
C: AUTH LOGIN
S: 334 VXNlcm5hbWU6
C: cm9vdA==
S: 334 UGFzc3dvcmQ6
C: dGVzdHBhc3N3b3JkCg==
S: 535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6
You must be somehow passing the wrong username string to MailKit because MailKit only uses whatever string you give to it as the username string. It doesn't have any logic to try and get the system username or anything like that.
Are you using the CredentialCache.DefaultCredentials
? e.g.:
client.Authenticate (CredentialCache.DefaultCredentials);
If so, that's the problem (and has nothing to do with MailKit).