Not allow to send email on behalf of my client on office365 - c#

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".

Related

How to send mail using code from Office365 when TLS is enabled?

My client has an account in Office365 and he recently added this account in the website he is using. Now he says that he cannot send mails using this account, whilst other accounts are OK. He says that TLS is enabled in the account. Anyhow, I am able to login to the mail account. I checked the settings and found that the SMTP settings are as follows:
Server name: smtp.office365.com
Port: 587
Encryption method: STARTTLS
This is a sample code that I am using to check.
String userName = "365useraccount";
String password = "password";
MailMessage msg = new MailMessage();
msg.To.Add(new System.Net.Mail.MailAddress("test#test.com"));
msg.From = new System.Net.Mail.MailAddress(userName);
msg.Subject = "Test Office 365 Account";
msg.Body = "Testing email using Office 365 account.";
msg.IsBodyHtml = true;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.office365.com";
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(userName, password);
client.Port = 587;
client.EnableSsl = true;
try
{
client.Send(msg);
}
catch
{
}
I am getting an exception with message:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [BMXPR01CA0043.INDPRD01.PROD.OUTLOOK.COM]
However, I am able to send mails using other Office365 accounts.
Any help of idea would be greatly appreciated

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.

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.

Mail sending through c#.Net getting error

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

Categories