Click here to Skip to main content
15,916,379 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i am sending to our company mails its working but if we use another mails like gmail,yahoo to send these mails its not working and i getting these error

Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server

My Code is:
C#
string smtp = "smtp.companyname.com";
string mailId = "xxx@companyname.com";
string pwd = "xxxx";
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            SmtpClient SmtpServer = new SmtpClient(smtp);
            mail.From = new MailAddress(mailId);
            mail.To.Add("yyy@gmail.com");
            mail.Subject = "Enquiry";
            mail.IsBodyHtml = true;
            mail.Body = "sdfsdfsd".ToString();
            SmtpServer.Credentials = new System.Net.NetworkCredential(mailId, pwd);
            SmtpServer.EnableSsl = false;
            SmtpServer.Send(mail);
Posted
Updated 6-Jun-13 1:03am
v2
Comments
Dharmendra Kumar Swarnkar 8-Sep-20 4:51am    
asda ada assfs adadad

1 solution

Refer to these links:

System.Net.Mail FAQ[^]

Sending Mail Using Net.Mail With Authentication[^]

how to send mail from local[^]

Try
C#
SmtpServer.EnableSsl = true;


Try the below code which uses gmail.
C#
MailMessage mail = new MailMessage();
mail.From = new MailAddress("gmail_Id@gmail.com");
mail.To.Add(new MailAddress(to_address));
mail.Subject = "your subject";
mail.IsBodyHtml = true;
mail.Body = Body here;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("gmail_Id@gmail.com", "12345");
smtp.EnableSsl = true;
smtp.Send(mail);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900