Hi Daniel,
You could try the following troubleshooting steps:
- Switch to Port 587 with STARTTLS
Port 465 uses implicit SSL, which is outdated and can be problematic in some hosting environments. Port 587 with STARTTLS is the modern, secure standard. MailKit example:
using MailKit.Net.Smtp;
using MimeKit;
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Your Name", "******@mydomain.com"));
message.To.Add(new MailboxAddress("Recipient", "recipient@example.com"));
message.Subject = "Test Email";
message.Body = new TextPart("plain") { Text = "Hello from .NET!" };
using var client = new SmtpClient();
client.Connect("smtp.gmail.com", 587, MailKit.Security.SecureSocketOptions.StartTls);
client.Authenticate("******@mydomain.com", "your-app-password");
client.Send(message);
client.Disconnect(true);
- Enable Detailed Logging
Add exception handling and logging to capture the exact error message when the app fails on IONOS. This will help pinpoint whether it’s a network issue, authentication failure, or TLS handshake problem.
- Test SMTP Connectivity from IONOS
Run a command like this from your IONOS server:
openssl s_client -connect smtp.gmail.com:587 -starttls smtp
If this fails, it’s likely a network or firewall issue despite IONOS’s assurances.
- Google Workspace Configuration
- Ensure the App Password is valid and not revoked.
- Check if SMTP relay is enabled in your Google Admin Console.
- Consider whitelisting your IONOS server IP under:
- Apps > Google Workspace > Gmail > Advanced settings > SMTP relay service
- DNS Records
SPF, DKIM, and DMARC are great for email deliverability but don’t affect SMTP authentication. Still, make sure your SPF record includes:
v=spf1 include:_spf.google.com ~all
Also as suggested my AgaveJoe, using the Gmail API is a more secure and scalable approach, especially for production apps.
Benefits:
- Uses OAuth2, eliminating the need for app passwords.
- Avoids SMTP limitations and firewall issues.
- Provides access to advanced Gmail features (labels, threads, attachments).
Getting Started:
- Register your app in Google Cloud Console.
- Use libraries like
Google.Apis.Gmail.v1
or MailKit with OAuth2.
- Follow the Gmail API Quickstart for .NET