I'm rather new to SMTP and IIS settings but according to the documentation on I've read the web this should be working.
What I'm trying to achieve: To send an email from the server to a users email using an existing SMTP Relay Server.
What I have done: In my IIS, for my site (ASP.NET), I have configured the SMTP E-mail. I have entered:
- A random E-mail address (it doesn't have to be an existing, right?)
- A SMTP Server IP (in this case an IP to an external SMTP Relay Server)
- A port number (25).
- Autentication Settings to "Not required".
My method for sending an email looks like this:
public static void SendEmail()
{
var message = new MailMessage()
{
Subject = "Heading",
Body = "Body",
message.From = new MailAddress("[email protected]");
message.To.Add("A valid email address"); //My own email address
}
var smtpClient = new SmtpClient("SMTP-Relay-Server-IP", 25); //Same IP as the one in SMTP E-mail configuration in IIS for the site.
smtpClient.Send(message);
}
}
Facts/questions:
- Is this correct? Is it correct to also put the Relay Server IP and Port number in the code as parameters in the new
SmtpClient? - I don't get an error but I don't receive an email. (I am 100% sure that the "to-email" is correct.
- What can be the reason for this not working? What am I missing or misunderstanding?