C# send yandex mail: 5.5.4 auth command first - c#

Everything was working until a few days ago.
Host : smtp.yandex.com
Port : 587
SmtpClient client = new SmtpClient(_emailConfiguration.SmtpServer, _emailConfiguration.Port);
client.UseDefaultCredentials = false;
client.TargetName = "Asam";
client.Credentials = new NetworkCredential(_emailConfiguration.From, _emailConfiguration.Password);
MailMessage message = new MailMessage(new MailAddress(_emailConfiguration.From, "Asam"), new MailAddress(email));
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
message.IsBodyHtml = true;
message.Subject = subject;
message.Body = body;
try
{
await client.SendMailAsync(message);
}
catch (System.Exception ex)
{
Console.WriteLine(ex);
}
But I'm getting this error : Bad sequence of commands. The server response was: 5.5.4 Error: send AUTH command first.
I logged in from https://mail.yandex.com/ my password is correct.

Related

Sending email over One.com

I am trying to send an email through a one.com mail server. With receiving one I have no problems.
however with sending I keep getting an SMTP Exception.
System.ApplicationException: 'SmtpException has occured: "failure sending mail"'
UPDATE: after a tip in the comments here is the inner Exception
WebException: Unable to connect to the remote server
This is my code
public void email_send(string sendTo)
{
try
{
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(sendTo));
msg.From = new MailAddress("myMail#mydomein.be", "my name");
msg.Subject = "This is a Test Mail";
msg.Body = "This is a test message";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("myMail#mydomein.be", "myPassword");
client.Port = 587;
client.Host = "mailout.one.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Send(msg);
Console.WriteLine("email was sent successfully!");
}
catch (SmtpException ex)
{
throw new ApplicationException
("SmtpException has occured: " + ex.Message);
}
catch (Exception ex)
{
throw ex;
}
}
I also have the following information form my email provider (one.com):
As discussed in the comments, it looks like you can only use mailout.one.com from One.com-hosted websites - it refuses connections from elsewhere.
Instead you need to use send.one.com from other connections, which supports the same set of ports.

unable to connect to the remote server c# - godaddy

I am trying to send mail from Web API using SMTP (GODaddy). It failed to send the mail and returning the exception as follows
Code :
public void SendMail()
{
try
{
MailMessage mail = new MailMessage("support#abc.com","toMail");
mail.Subject = "Subject";
mail.IsBodyHtml = true;
mail.Body = "this is email body";
SmtpClient client = new SmtpClient("relay-hosting.secureserver.net");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("support#abc.com", "****");
client.Port = 25;
client.Send(mail);
}
catch (SmtpFailedRecipientException Ex)
{
Ex.FailedRecipient.ToString();
}
}
Can anyone help me to fix this.

C# - Failure sending mail

This code works fine on my local machine ut when I deploy it. it gives Failure sending mail error.. Please Help...
MailAddress addrsTo = new MailAddress(toEmail);
MailAddress addrsFrom = new MailAddress("XXX#XXX.com", "XXX Title");
MailMessage mailmsg = new MailMessage(addrsFrom, addrsTo);
mailmsg.Subject = mailSbjct;
mailmsg.Body = "XXX Body";
SmtpClient smtp = new SmtpClient("mail.XXX.com");
smtp.EnableSsl = false;
smtp.Port = 26;
smtp.Credentials = new NetworkCredential("XXX#XXX.com", "XXXXXXX");
try {
smtp.Send(mailmsg);
} catch (Exception exc) {
throw new XXXException(1234, "---" + exc.Message);
}
you can try this, if you are using gmail :
MailMessage mail = new MailMessage();
mail.Subject = "Your Subject";
mail.From = new MailAddress("senderMailAddress");
mail.To.Add("ReceiverMailAddress");
mail.Body = "Hello! your mail content goes here...";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
NetworkCredential netCre = new NetworkCredential("SenderMailAddress","SenderPassword" );
smtp.Credentials = netCre;
try
{
smtp.Send(mail);
}
catch (Exception ex)
{
}
As you have mentioned in your question works fine on my local machine.
It is suggesting that the problem is of credential which you are providing to send the mail.
Edit 1
If you are using you own domain credential then it is not going to work on the server.
The user IIS should have enough authority to send mail.
IIS User More detail
http://www.iis.net/learn/get-started/planning-for-security/understanding-built-in-user-and-group-accounts-in-iis
Here is a SO link
How to send email through IIS7?

Email not being sent from C# using gmail a/c

The email is not being sent from C# code using the gmail smtp settings. It is giving an error of "Server requires a Secure connection or the Client was not authenticated."
The email and password are same as used for Login..
Following is the complete code.
MailMessage mail = new MailMessage("<from>","<to>");
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.Credentials = new NetworkCredential("<email>", "<password>");
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Timeout = 20000;
client.UseDefaultCredentials = false;
mail.Body = "Test email from C# Code";
mail.Subject = "Test Email";
Console.WriteLine("Attempting to Send Email");
try {
client.Send(mail);
Console.WriteLine("Email sent... ");
}
catch (System.Net.Mail.SmtpFailedRecipientException ex) {
Console.WriteLine("Could not send email to the mentioned recipient" + ex.Message);
}
catch (System.Net.Mail.SmtpException ex) {
Console.WriteLine("Could not send Email..\n" + ex.Message + "\n" + ex.StackTrace);
}
Console.ReadLine();
Any help appreciated :) -- Kind regards,
You have to swap the following lines.
client.Credentials = new NetworkCredential("<email>", "<password>");
client.UseDefaultCredentials = false;
You have to set the UseDedaultCredentials property at first.
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("<email>", "<password>");
That's the way, it should work.

Problem in Sending Email using Gmail Settings

I can't send a email message using gmail settings. i already tried client.Host ="localhost" it's working but not in client.Host ="smtp.gmail.com".. Please help me guys.. I need use client.Host ="smtp.gmail.com".. thanks
here's my C# code:
string from = "aevalencia119#gmail.com"; //Replace this with your own correct Gmail Address
string to = "aevalencia191#gmail.com"; //Replace this with the Email Address to whom you want to send the mail
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to); mail.From = new
MailAddress(from, "One Ghost" ,System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail" ;
mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.Body = "This is Email Body Text";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true ; mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient(); //Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(from, "iseedeadpoeple");
client.Port = 587; // Gmail works on this port client.Host ="smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
client.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
} HttpContext.Current.Response.Write(errorMessage
);
} // end try
here's the error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Much thanks guys!
You need to get and send mail to GMail by using SSL secutiry certificate
MailMessage msgMail = new MailMessage("a#gmail.com", "b#mail.me", "subject", "message body");
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential("a#gmail.com", "a");
try
{
smtp.Send(msgMail);
}
catch (Exception ex)
{
}
reference: http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/28b5a576-0da2-42c9-8de3-f2bd1f30ded4
public static string sendMail(string to, string title, string subject, string body)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient();
if (to == "")
to = "aevalencia119#gmail.com";
MailAddressCollection m = new MailAddressCollection();
m.Add(to);
mail.Subject = subject;
mail.From = new MailAddress( "aevalencia119#gmail.com");
mail.Body = body;
mail.IsBodyHtml = true;
mail.ReplyTo = new MailAddress("aevalencia119#gmail.com");
mail.To.Add(m[0]);
smtp.Host = "smtp.gmail.com";
client.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("aevalencia119#gmail.com", "####");
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
smtp.Send(mail);
return "done";
}
catch (Exception ex)
{
return ex.Message;
}
}

Categories

Resources