C# SMTP enviado desde un servidor que no está en el mismo dominio que Exchange está en blanco
Frecuentes
Visto 823 veces
1
I've just written a piece of code for a MVC website that sends a SMTP email using the .NET SmtpClient
via our Exchange server. The email it sends has a HTML body with links to images and a file that are hosted on the website.
The email is sent fine when run internally on our network, but when its run from the hosted server that's not on our domin, the email comes through but the body is blank. Does anybody have any idea why? Is is because of the linked images or file that could be a potential threat and come from a server not on the domain and so is not trusted?
Here's the code that sends the email, it uses the MailDefinition
class to insert a link to a file into the body that they've requested to download:
MailDefinition md = new MailDefinition();
md.From = "test@testing.com";
md.Subject = "Test Email";
md.IsBodyHtml = true;
ListDictionary replacements = new ListDictionary();
replacements.Add("REQUESTED_LINK", @"C:\MyFile.pdf");
MailMessage email = md.CreateMailMessage(mailTo, replacements, content, new System.Web.UI.Control());
SmtpClient emailClient = new SmtpClient();
emailClient.Host = "MyExchangeServer";
emailClient.Send(email);
2 Respuestas
1
My guess is Value for MailDefinition.BodyFileName
missing from the code.
The name of the file that contains the message body text. The default is Empty.
On development or in internal sevrer BodyFileName
has a some value. On hosted sevrer file is missing so email Body is empty.
mira esto Example for reference
Respondido el 12 de junio de 12 a las 11:06
Close, the body of the email was being passed though in the 'content' parameter, but it turns out the file containing the email body hadn't been deployed, and so 'content' was empty - sala de iain
0
Fixed, turns out the .html file containing the body of the email hadn't been deployed to the live server, and so the body of the email was blank as a result. Adding it fixed the problem, so it turns out it wasn't a security issue after all. Thanks for your help
Respondido el 12 de junio de 12 a las 12:06
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# asp.net-mvc email smtp exchange-server or haz tu propia pregunta.
Is the body truly empty or is the HTML not rendered by your client? What client did you use to check this? Can you save the message to a file and check what's in the body? You should probably add some plain text description in your message anyway to account for such cases. - Panagiotis Kanavos
It appears to be truly empty. I've tested this with exchange 2010, saved the email as plain text, opened it up and its got sections for the From, To, Sent Date and Subject but no Body. I've also sent it to my Hotmail account and it appears blank there too, although I'm not sure how to test it any further from there. - Iain Ward
Can you even send pure HTML messages? Perhaps your hoster is blocking event those. - Panagiotis Kanavos