Mail sending through c#.Net getting error - c#

I want to select file and send to employees.
employee's(recipient) email I am reading from excel.
Sender's email is set to my code.
MailMessage mail = new MailMessage();
mail.Attachments.Add(new System.Net.Mail.Attachment(attach));
mail.To.Add(sendmail);
mail.From = new MailAddress(SenderEmail);
mail.Subject = "Payroll";
string body = "Hi, payroll";
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("sendermail", "pwd");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Send(mail);
Now I want to read sender's email & password from a textbox,and pass.
Now error occuring like this
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
I coded smtpclient host as gmail and corresponding port.
But I want to send from other account means in yahoo,live etc..
How can it possible? But even gmail is also giving error.Can anybody help?
error is getting when reading from textbox

Related

Not allow to send email on behalf of my client on office365

I have tried to send email to my client's customers with my client from address(info#myclient.com).
and my client has already configured my smtp server via SPF to their domain.
Following is C# code written to send the email.
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("info#mycient.com");
mail.To.Add("krishna.menan#gmail.com");
mail.Subject = "This is an email";
mail.Body = "this is a sample body with html in it. <b>This is bold</b>
<font color=#336699>This is blue</font>";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
System.Net.NetworkCredential networkCredentialRFE = new
System.Net.NetworkCredential("kirshna#mycomapny.com", "Password123");
smtp.Credentials = networkCredentialRFE;
smtp.Host = "outlook.office365.com";
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.Send(mail);
Following is error I am getting:
Mailbox unavailable. The server response was: 5.7.60 SMTP; Client does not have permissions to send as this sender
Make sure that the taskuser you are using has the proper "send as" permissions, see "Give mailbox permissions to another user in Office 365 - Admin Help".

Can't send email using SMTP

I'm trying to send an email via .net smtp. I am receiving this message:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("server", 587);
SmtpServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.EnableSsl = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
mail.From = new MailAddress(FromMail);
mail.To.Add("emailaddress");
mail.Bcc.Add("emailaddress");
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpServer.Send(mail);
The issue I believe is that the servers are located in the DMZ...anyone have any insight on how to fix this? If we assign the user with domain admin rights, the emails work...due to security reasons we don't want to go that route.
Issue resolved...the network team didn't have port 587 available...once they added it, emails started working for anonymous sender. I no longer need to use credentials. Thanks to all who replied.

C# "Additional information: The SMTP server requires a secure connection or the client was not authenticated."

So im trying to send an email on C# and always getting the same error: "Additional information: The SMTP server requires a secure connection or the client was not authenticated." i have checked out pretty much every single link i could find about this i have diabled all gmail protection and my credentials are correct i don't know why this error continues
MailMessage mail = new MailMessage();
mail.From = new MailAddress("xx#gmail.com");
mail.Sender = new MailAddress("xx#gmail.com");
mail.To.Add("external#emailaddress");
mail.IsBodyHtml = true;
mail.Subject = "Email Sent";
mail.Body = "Body content from";
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("xx#gmail.com", "xx");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Timeout = 30000;
try
{
smtp.Send(mail);
}
catch (SmtpException ex)
{
MessageBox.Show(ex.Message.ToString());
}
This is the exception message from C#, what is the actual response from the server? You may need to enable "less secure apps" to connect to your gmail account first (see https://www.google.com/settings/security/lesssecureapps).
I have tried your code getting the error "5.5.1 Authentication required". Please give this link a try Sending email through Gmail SMTP server with C#

The SMTP server requires a secure connection when i try to send an email

Hi guys I create a mail class to send emails.
public void SendEmail(string subject, string messageBody, string toAddress)
{
MailMessage mail = new MailMessage();
mail.To.Add(toAddress);
//mail.To.Add("amit_jain_online#yahoo.com");
mail.From = new MailAddress("noreply3ncra#gmail.com");
mail.Subject = subject;
string Body = messageBody;
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = false;
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential
("noreply3ncra#gmail.com", "********");
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
smtp.Send(mail);
}
But I got this error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
So I have to sign into Gmail and enter the captcha code and after this every thing is going to be ok.
What should I do?
Try this:
You should enable application to access gmail account.
Try this link:
Gmail allow access
For more info refer this link:
Stackoverflow link
Add this also:
Add port no also to your code as:
smtp.Port = 587;
For more info refer this link:
Codeproject link

Unable to connect to the remote SMTP server

SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.Credentials = new System.Net.NetworkCredential("gmailId", "Password");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("gmailId", "Testing Mail");
mail.To.Add(new MailAddress("someMailId"));
mail.Body = "This is a test email. Please ignore or delete.";
mail.Subject = "Mail Testing";
smtpClient.Send(mail);
I am trying to use the code above to send mail. It was working fine for me, but when I tried to use it in another system it gave me an error ("Unable to connect to the remote server").
I think your gmail account is secured with mobile sms facility. If you access your gmail account from other macine than a sms will recieve from gmail for varification.
Please off this functionality and try again.

Categories