Steam Steam - 6 months ago 10
Java Question

Sending mails from an SMTP server

I know that to send an e-mail from an SMTP server, one needs a server address, password and username/default credentials. But, does SMTP also have a password to access the server itself ? Is there a username as well ?

Answer

All you need is

  • hostname: smtp.servername.com
  • port: 25 or 465 (depending on if SSL)
  • username: myuser
  • password: mypassword

You do not need a password to the "server itself" or anything like that.

Depending on the server config, the email you send "from" may or may not need to be a valid email address on that server.

EDIT: basic C# implementation

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("luckyperson@online.microsoft.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("yourmailuser@yourhost.com",25);
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
// if you need user/pass login
client.Credentials = new NetworkCredential("username","password");
smtp.Send(message);
Comments