Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am sending a .PDF file as an Email attachment to a SharePoint document library using SmtpClient and MailMessage.

I provide the credentials of the sender for authentication but yet I am getting the exception mentioned in the subject.

What is wrong and what can I do instead? Is it mandatory to provide a sender account?

What I have tried:

C#
MailMessage mailSharePoint = new MailMessage();

SmtpClient smtpClientSharePoint = new SmtpClient("server30.company.local", 25);

smtpClientSharePoint.Credentials = new System.Net.NetworkCredential("glpi@company.com", password);

smtpClientSharePoint.UseDefaultCredentials = true;

smtpClientSharePoint.DeliveryMethod = SmtpDeliveryMethod.Network;

smtpClientSharePoint.EnableSsl = true;

mailSharePoint.From = new MailAddress("glpi@company.com", "Save file To SharePoint");

mailSharePoint.To.Add(new MailAddress("fdf@server25.company.local"));

mailSharePoint.Subject = "Save file to SharePoint " + myModel.id_fdf_offers;

mailSharePoint.Attachments.Add(new Attachment(Server.MapPath("~/TEMPLATE/" + FileName + ".pdf")));

smtpClientSharePoint.Send(mailSharePoint);
Posted
Updated 11-May-18 5:35am

You need to contact whoever administers the smtp server you are using ("server30.company.local") and tell them you want to relay from the company.com domain and follow their advice. They might flat out say you can't, they might be able to configure their server to allow this, they might give you a special set of credentials you can use. We are not the administrator for that server so can't tell you what will happen.
 
Share this answer
 
v2
Very likely the SMTP provider (in your example company.com) has SPF setup. Which is a good and beautiful thing.

What is SPF? "Sender Policy Framework (SPF) is a simple email-validation system designed to detect email spoofing by providing a mechanism to allow receiving mail exchangers to check that incoming mail from a domain comes from a host authorized by that domain's administrators"

In your case, the originator (From) is "glpi@company.com" and the host/domain that send the email is "server30.company.local". Then the policy kick in and said, hey "server30.company.local" is not permitted/allow to send email on behalf of "company.com". Failed it. You might need to contact the Administrator to allow the "server30.company.local" domain to use "company.com" SMTP to send email.

Sender Policy Framework - Wikipedia[^]

How to update/set SPF
Set up SPF in Office 365 to help prevent spoofing: Exchange Online Help[^]
Add an SPF record | Domains - GoDaddy Help CA[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900