As the title says, I am sending email from my ASP.net web application without any attachment (for now) but strangely the body of email is going as a separate HTML file attached to blank email like when I click the HTML file it opens the body in separate window with everything that I have written in body as standalone HTML file, this is only happening when I send email to some portals like e-lance but when I send it to gmail or hotmail address then email is going perfectly with no attachment and body-text appearing where it should.
My email code is
public bool sendMail(string messageSubject, System.Net.Mail.MailAddress fromEmailAddress, System.Net.Mail.MailAddress toEmailAddress, string source_id, string messageText)
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.IsBodyHtml = true;
mail.Subject = messageSubject;
mail.From = fromEmailAddress;
mail.To.Add(toEmailAddress);
mail.Body = messageText;
SmtpClient relayServer = new SmtpClient();
List<KeyValuePair<string, string>> commandParameters = new List<KeyValuePair<string,string>>();
commandParameters.Add(new KeyValuePair<string,string>("@source_id", source_id));
DataTable sourcesTable = SQLSelect("SELECT * FROM LogiCrmSources WHERE source_id = @source_id", commandParameters);
relayServer.Host = sourcesTable.Rows[0]["source_smtp"].ToString();
relayServer.Port = Convert.ToInt16(sourcesTable.Rows[0]["source_smtp_port"].ToString());
if (relayServer.Port == 25)
{
relayServer.EnableSsl = false;
}
else
{
relayServer.EnableSsl = true;
}
relayServer.Credentials = new System.Net.NetworkCredential(sourcesTable.Rows[0]["source_email"].ToString(), sourcesTable.Rows[0]["source_password"].ToString());
try
{
relayServer.Send(mail);
return true;
}
catch(SmtpFailedRecipientException exp)
{
return false;
}
}
Not all clients can handle html emails properly. Gmail for example can while the portals you mention can’t. In those cases the body of the email as sent as an attachment.