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.
Related
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.
this is my code:
try {
SmtpClient client = new SmtpClient("smtp.aruba.it", 25);
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("receiver#pec.it", "password");
MailMessage msg = new MailMessage();
msg.To.Add("receiver#pec.it"); //Receiver
msg.From = new MailAddress("sender#pec.it"); //Sender
msg.Subject = "Object"; //Oggetto Mail
msg.Body = ""; //Corpo del testo
Attachment data = new Attachment(fileName);
msg.Attachments.Add(data);
client.Send(msg);
MessageBox.Show("Attachment send correctly");
}
catch (SmtpException ex)
{
throw new ApplicationException
("SmtpException has occured: " + ex.Message);
}
I tried to use this code but it doesn't work. I tried with gmail host and it works, so the code should work. The problem is smtp for sure but I couldn't find the right way to send it via pec aruba.
Another problem is the attachment. The name of attachment is the entire filename path and i want that is only the name of the file. How i can resolve this two problem?
Use smtps.aruba.it instead smtp.aruba.it and port 587. It works for me ( I had same problem)
I've tried this code to send Email without entering credentials :
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp server");
mail.From = new MailAddress("sender email");
mail.To.Add("receiver email");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
SmtpServer.Port = 587;
SmtpServer.Credentials = CredentialCache.DefaultNetworkCredentials;
SmtpServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
I get this server error:
Sytem.Net.Mail.SmtpException 5.7.3 Requested action aborted;user not
authentificated
I've also tried:
SmtpServer.UseDefaultCredentials = false;
Still the same exception is thrown.
my code:
private void button1_Click(object sender, EventArgs e)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("mymail#gmail.com", "mypassword");
client.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("mymail#gmail.com", "SMTP Test");
mail.To.Add(new MailAddress("mymail#gmail.com"));
mail.Subject = "Subject test";
mail.Body = "Body test";
client.Send(mail);
MessageBox.Show("mail send.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I get this error:
I cant upload images yet so i use puush.
http://puu.sh/fpAnF/d4372b0b55.png
Error a bit translated:
Error when sending e-mail. system.net.mail.smtpexception: error when
sending e-mail. ---> system.net.webexception: can't connect to the
external server ---> system.net.sockets.sochetexception: can't connect
because the goalcomputer (dont know the exact translation of that) the
connection actively has refused.
can somobody please help me?
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.