Sending Mail in C#
-
Dear Sirs, Please guide me how I can send Mails in .NET via an SMTP Server which requires SMTP Authentication. Regards, Sassan Komeili Zadeh
-
Dear Sirs, Please guide me how I can send Mails in .NET via an SMTP Server which requires SMTP Authentication. Regards, Sassan Komeili Zadeh
Hmm... There have been umpteen articles on this topic in C#.
MailMessage msg = new MailMessage();
msg.From = "crawler@deepak.portland.co.uk";
msg.To = "crawler@deepak.portland.co.uk";
msg.Subject = "Test";
msg.Body = "Hi! Hello" +"\nSent Via MailMessage and SmtpMail Class";
SmtpMail.SmtpServer = "smtp.yourmailserver.yourisp.com";
SmtpMail.Send(msg);
SmtpMail.Send("crawler@deepak.portland.co.uk","crawler@deepak.portland.co.uk","Test","Hi! Hello\nSent Via SmtpMail class");Include System.Web.Mail namespace for the above methods to be visible to the compiler. Deepak Kumar Vasudevan http://deepak.portland.co.uk/
-
Hmm... There have been umpteen articles on this topic in C#.
MailMessage msg = new MailMessage();
msg.From = "crawler@deepak.portland.co.uk";
msg.To = "crawler@deepak.portland.co.uk";
msg.Subject = "Test";
msg.Body = "Hi! Hello" +"\nSent Via MailMessage and SmtpMail Class";
SmtpMail.SmtpServer = "smtp.yourmailserver.yourisp.com";
SmtpMail.Send(msg);
SmtpMail.Send("crawler@deepak.portland.co.uk","crawler@deepak.portland.co.uk","Test","Hi! Hello\nSent Via SmtpMail class");Include System.Web.Mail namespace for the above methods to be visible to the compiler. Deepak Kumar Vasudevan http://deepak.portland.co.uk/
Deepak Kumar Vasudevan wrote: There have been umpteen articles on this topic in C#. But he was asking about SMTP with authentication....;P MyDUMeter: a .NET DUMeter clone
-
Dear Sirs, Please guide me how I can send Mails in .NET via an SMTP Server which requires SMTP Authentication. Regards, Sassan Komeili Zadeh
Try adding the username and password to the front of the URl of the SMTP server. eg
user:pass@smtp.isp.net
Not sure if it will work though. MyDUMeter: a .NET DUMeter clone -
Try adding the username and password to the front of the URl of the SMTP server. eg
user:pass@smtp.isp.net
Not sure if it will work though. MyDUMeter: a .NET DUMeter cloneThanks. My Mail Server POP3 account username is: info@xyz.com and when I try what you suggested, I get no answer. Would you suggest another solution? Regards, Sassan
-
Dear Sirs, Please guide me how I can send Mails in .NET via an SMTP Server which requires SMTP Authentication. Regards, Sassan Komeili Zadeh
You may use this class and add the following code to authenticate, just after sending the HELO command:
//introduce ourselves buf.Append("HELO "); buf.Append(host); con.SendCommand(buf.ToString()); con.GetReply(out response, out code); buf.Length = 0; if(!AuthLoginPlain(con, user, password)) { // Failed con.Close(); throw .... // throw an error } ... private bool AuthLoginPlain(SmtpConnection con, string user, string pass) { //Envia o comand AUTH LOGIN StringBuilder buf = new StringBuilder(); byte [] b_user = System.Text.Encoding.ASCII.GetBytes(user); byte [] b_pass = System.Text.Encoding.ASCII.GetBytes(pass); string response; string res; string data; int code; buf.Append("AUTH LOGIN"); con.SendCommand(buf.ToString()); con.GetReply(out response, out code); buf.Length = 0; if(code == 334) { //pega ultima resposta menos o codigo de resposta response = response.Substring(4); res = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(response)); if(res == "Username:") { //envia o nome de data = Convert.ToBase64String(b_user); buf.Append(data); con.SendCommand(buf.ToString()); con.GetReply(out response, out code); buf.Length = 0; } if(code != 334) { return false; } response = response.Substring(4); res = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(response)); if(res == "Password:") { // manda senha em plain data = Convert.ToBase64String(b_pass); buf.Append(data); con.SendCommand(buf.ToString()); con.GetReply(out response, out code); if(code != 235) { // falhou! return false; } // se chegou até aqui, ok! return true; } } return false; }
Cheers, John