gmail replay using smtp client thread not created - c#

I'm trying to send replay email using smtp client ,replay sent successfully but thread not created for mail , i need below replay see this link https://ibb.co/drSCMp
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new
System.Net.NetworkCredential("username", "password");
MailMessage mm = new MailMessage("username", "recieverusername, "Re:subject", "Replay From c#");
mm.Headers.Add("In-Reply-To", "<messageid>");
mm.Headers.Add("References", "<messageid>");
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.Send(mm);

Related

c# MimeKit mail not sent without error. System.Net.Mail works fine

I made a console application to test MimeKit, it's executed without errors but emails never arrives.
i usae same data with System.Net.Mail and all works fine.
What can be the problem?
MimeKit code:
var email = new MimeMessage();
email.Sender = MailboxAddress.Parse("aa#sbb.com");
email.To.Add(MailboxAddress.Parse("aa.cc#dd.com"));
email.To.Add(MailboxAddress.Parse("bb.dd#dd.com"));
email.Subject = "test";
var builder = new BodyBuilder();
builder.HtmlBody = "corpo";
email.Body = builder.ToMessageBody();
using var smtp = new SmtpClient();
smtp.Connect("smtp.xxx.com", 25, SecureSocketOptions.None);
smtp.Authenticate("ut", "pwd");
smtp.SendAsync(email);
smtp.Disconnect(true);
Console.WriteLine("Email Sent.");
System.mail code:
using (MailMessage mm = new MailMessage())
{
mm.To.Add(new MailAddress("aa.cc#dd.com"));
mm.To.Add(new MailAddress("bb.dd#dd.com"));
mm.From = new MailAddress("aa#sbb.com", "You");
mm.ReplyToList.Add("aa#sbb.com");
mm.Subject = "vecchia mail";
mm.Body = "con system.mail";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.xxx.com";
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential NetworkCred = new NetworkCredential("ut", "pwd");
smtp.Credentials = NetworkCred;
smtp.Port = 25;
Console.WriteLine("Sending Email......");
smtp.Send(mm);
Console.WriteLine("Email Sent.");
}
Thanks to #Klaus Gütter i got the error and then find the solution: a security rule that prevent connection between development machine and mail server, once deployed the application in test environment all works fine.
thanks for suggestions

Why am I getting a connection timed out when trying to send an email through a CS program?

Firewall: Turned OFF. I am getting a connection timed out error. The email and password are verified.
The exception is: System.Net.Mail.SmtpException : The operation has timed out.
My code
string filename = #"C:\emailsample.htm";
string mailbody = System.IO.File.ReadAllText(filename);
mailbody = mailbody.Replace("##NAME##", firstname.Text);
string to = emailid.Text;
string from = "xxx.abc45#gmail.com";
MailMessage message = new MailMessage(from, to);
message.Subject = "Auto Generated Mail";
message.Body = mailbody;
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com", 465);
System.Net.NetworkCredential basic = new System.Net.NetworkCredential(from, "Password");
client.EnableSsl = true;
client.Timeout = 20000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = basic;
try
{
client.Send(message);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.ToString());
return;
}
Try modifying the Port to 587.
Also verify if the From email is correct.
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("user#gmail.com","password");
MailMessage mm = new MailMessage("donotreply#domain.com", "sendtomyemail#domain.co.uk", "test", "test");
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.Send(mm);

sending email using gmail from asp.net

I am trying to send mail using gmail in asp.net
My Code:
using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
{
mm.Subject = txtSubject.Text;
mm.Body = txtBody.Text;
if (fuAttachment.HasFile)
{
string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
}
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
But i am getting error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
where is my error?
You can try the below suggestions:
Try setting "UseDefaultCredentials" to "False" smtp.UseDefaultCredentials = false;
Try logging to your Gmail account, it may be blocking the access.
Try enabling access to your Gmail account, see this link for more information http://email.about.com/od/gmailtips/qt/How-To-Unlock-Gmail-For-A-New-Email-Program-Or-Service.htm
Change "smtp.UseDefaultCredentials = true;" to "smtp.UseDefaultCredentials = false;". Or test your gmail account with code below.
using (MailMessage mm = new MailMessage(new MailAddress("sender#example.com"), new MailAddress("recipient#example.com")))
{
mm.Subject = "test";
mm.Body = "body test";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential NetworkCred = new NetworkCredential("sender#example.com", "password");
smtp.UseDefaultCredentials = false;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
UPDATE
Go to: google.com/settings/security?hl=en_GB and if field "Access for less secure apps" is Disabled click settings and change it to enabled... Then test your connection with code above. It worked for me on new gmail user

System.Security.Cryptography.CryptographicException: The handle is invalid

I am getting exception while sending mail through C# for
SmtpClient client = new SmtpClient()
as System.Security.Cryptography.CryptographicException: The handle is invalid.
MailMessage mail = new MailMessage(from,to);
mail.To.Add(to);
mail.From = new MailAddress(from, "", System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = fr.message;
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, Password);
client.Port = 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
client.Send(mail);
I am not getting why this happens?
Check your project settings and make sure you have checked NTLM Authentication:

Sending text to different email server

SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("myname#gmail.com", "Lenin");
smtpClient.Host = "localhost";
//smtpClient.Host = "";
//smtpClient.Port = 25;
message.From = fromAddress;
message.To.Add("myname#gmail.com");
message.Subject = "Feedback";
//message.CC.Add("admin1# gmail.com");
//message.CC.Add("admin2# gmail.com");
// message.Bcc.Add(new MailAddress("admin3# gmail.com"));
// message.Bcc.Add(new MailAddress("admin4# gmail.com"));
message.IsBodyHtml = false;
message.Body = txtComments.Text;
smtpClient.Send(message);
MessageBox.Show("Email successfully sent.");
}
catch (Exception ex)
{
MessageBox.Show("Send Email Failed." + ex.Message);
}
please help to sent email to different server .. gmail.com/yahoo.com/inbox.com ..etc using windows application.
thanks for the help.
SmtpClient smtpClient = new SmtpClient(host, port);
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("username#gmail.com", "password");
client.EnableSsl = true;
client.Host = "smtp.gmail.com";
client.Port = 465 or 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(MailMessage);
try this one.

Categories

Resources