ASP.NET - error in sending email - Asked By asif hameed on 10-Jan-10 01:49 AM

Hi all,

I am sending a formatted email using asp.net and I am getting following error:

Transaction failed. The server response was: The message was rejected because it contains prohibited virus or spam content

I am using inline css. What can cause this error ? Below is my code :

  public static string GenerateQuoteBody(string quoteDate, string quoteExpires, string quoteNumber, string originCity, string originState, string destCity, string destState, string year, string carMake, string carModel, string condition, string year2nd, string carMake2nd, string carModel2nd, string condition2nd, string serviceType, string carrierType, string deposit, string fromName, string fromEmail, bool sendSecond)
        {
            string strEmail = null;

            strEmail = strEmail + "<html>";
            strEmail = strEmail + "<head>";
            strEmail = strEmail + "<title></title>";
            strEmail = strEmail + "</head>";
            strEmail = strEmail + "<body style=\"margin: 10px; font-family: Verdana; font-size: 14px; color: black;\">";
            strEmail = strEmail + "<table summary=\"parent table\" align=\"center\" style=\"width: 100%;\">";
            strEmail = strEmail + "<tr style=\"padding: 15px; vertical-align: middle;\">";
            strEmail = strEmail + "<td width=\"50%\" align=\"center\">";
            strEmail = strEmail + " <img alt=\"logo\" src=\"http://abc.com/images/TWMLogo.jpg/" style=\"width: 470px; height: 240px\" />";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "<td width=\"50%\" align=\"right\" valign=\"middle\">";
            strEmail = strEmail + "<table cellpadding=\"5\" cellspacing=\"0\" style=\"width: 75%;\">";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td style=\"font-size: 22px; font-family: Tahoma; font-weight: bolder; padding: 5px;";
            strEmail = strEmail + "text-align: left; line-height: 1em;\">";
            strEmail = strEmail + "Quote Date:" + quoteDate;
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td style=\"font-size: 22px; font-family: Tahoma; font-weight: bolder; padding: 5px;";
            strEmail = strEmail + "text-align: left; line-height: 1em;\">";
            strEmail = strEmail + "Quote Expires:" + quoteExpires;
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td style=\"font-size: 22px; font-family: Tahoma; font-weight: bolder; padding: 5px;";
            strEmail = strEmail + "text-align: left; line-height: 1em;\">";
            strEmail = strEmail + "Quote Number: " + quoteNumber;
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "</table>";
            strEmail = strEmail + "&nbsp;";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\" style=\"font-family: Arial Black\">";
            strEmail = strEmail + "<h1>";
            strEmail = strEmail + "VEHICLE TRANSPORTATION QUOTE";
            strEmail = strEmail + "</h1>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\">";
            strEmail = strEmail + "<hr style=\"border: 0; width: 100%; height: 3px; color: Black;\" />";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<th colspan=\"2\" style=\"padding: 10px; background-color: white;\">";
            strEmail = strEmail + "<div style=\"background-color: #e0e0d6; text-align: left\" style=\"line-height: 1.5em;";
            strEmail = strEmail + "font-weight: bolder; font-size: 24px; font-family: Tahoma;\">";
            strEmail = strEmail + "Thank you for your interest in our services. Based on the information you provided";
            strEmail = strEmail + "we’ve determined your quote to be as follows:";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "&nbsp;";
            strEmail = strEmail + "</th>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr align=\"center\">";
            strEmail = strEmail + "<td colspan=\"2\">";
            strEmail = strEmail + "<table cellpadding=\"0\" cellspacing=\"0\" style=\"width: 75%;\">";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td width=\"30%\" style=\"padding: 5px; font-weight: bold; text-align: center; font-size: 20px;\">";
            strEmail = strEmail + "<div style=\"background-image: url(http://abc.com/images/from.png); width: 260px;";
            strEmail = strEmail + "height: 189px;\">";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "<td width=\"70%\" style=\"padding: 5px; font-weight: bold; text-align: left; background-image: url(http://abc.com/images/background.png);";
            strEmail = strEmail + "width: 630px; height: 149px; vertical-align: middle;\">";
            strEmail = strEmail + "<div style=\"line-height: 1.5em; font-weight: bolder; font-size: 24px; font-family: Tahoma;\">";
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "&nbsp;. City:" + originCity;
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "&nbsp;. State:" + originState;
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td>";
            strEmail = strEmail + "&nbsp";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td width=\"30%\" style=\"padding: 5px; font-weight: bold; text-align: center; font-size: 20px;\">";
            strEmail = strEmail + "<div style=\"background-image: url(http://abc.com/images/to.png); width: 260px;";
            strEmail = strEmail + "height: 189px;\">";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "<td width=\"70%\" style=\"padding: 5px; font-weight: bold; text-align: left; background-image: url(http://abc.com/images/background.png);";
            strEmail = strEmail + "width: 630px; height: 149px; vertical-align: middle;\">";
            strEmail = strEmail + "<div style=\"line-height: 1.5em; font-weight: bolder; font-size: 24px; font-family: Tahoma;\">";
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "&nbsp;. City:" + destCity;
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "&nbsp;. State:" + destState;
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td>";
            strEmail = strEmail + "&nbsp";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td width=\"30%\" style=\"padding: 5px; font-weight: bold; text-align: center; font-size: 20px;\">";
            strEmail = strEmail + "<div style=\"background-image: url(http://abc.com/images/vehicleinfo.png);";
            strEmail = strEmail + "width: 250px; height: 189px;\">";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "<td width=\"70%\" style=\"padding: 5px; font-weight: bold; text-align: left; background-image: url(http://abc.com/images/background.png);";
            strEmail = strEmail + "width: 630px; height: 189px; vertical-align: middle;\">";
            strEmail = strEmail + "<div style=\"line-height: 1.5em; font-weight: bolder; font-size: 24px; font-family: Tahoma;\">";
            strEmail = strEmail + "&nbsp;. Year: 2006";
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "&nbsp;. Make:" + carMake;
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "&nbsp;. Model:" + carModel;
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "&nbsp;. Condition:" + condition;
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td>";
            strEmail = strEmail + "&nbsp";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";

            if (sendSecond)
            {
                strEmail = strEmail + "<tr>";
                strEmail = strEmail + "<td width=\"30%\" style=\"padding: 5px; font-weight: bold; text-align: center; font-size: 20px;\">";
                strEmail = strEmail + "<div style=\"background-image: url(http://abc.com/images/vehicleinfo.png);";
                strEmail = strEmail + "width: 250px; height: 189px;\">";
                strEmail = strEmail + "</div>";
                strEmail = strEmail + "</td>";
                strEmail = strEmail + "<td width=\"70%\" style=\"padding: 5px; font-weight: bold; text-align: left;\" style=\"background-image: url(http://abc.com/images/background.png);";
                strEmail = strEmail + "width: 630px; height: 149px; vertical-align: middle;\">";
                strEmail = strEmail + "<div style=\"line-height: 1.5em; font-weight: bolder; font-size: 24px; font-family: Tahoma;\">";
                strEmail = strEmail + "&nbsp;. Year: 2006";
                strEmail = strEmail + "<br />";
                strEmail = strEmail + "&nbsp;. Make:" + carMake2nd;
                strEmail = strEmail + "<br />";
                strEmail = strEmail + "&nbsp;. Model:" + carModel2nd;
                strEmail = strEmail + "<br />";
                strEmail = strEmail + "&nbsp;. Condition:" + condition2nd;
                strEmail = strEmail + "</div>";
                strEmail = strEmail + "</td>";
                strEmail = strEmail + "</tr>";
                strEmail = strEmail + "<tr>";
                strEmail = strEmail + "<td>";
                strEmail = strEmail + "&nbsp";
                strEmail = strEmail + "</td>";
                strEmail = strEmail + "</tr>";
            }
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td width=\"30%\" style=\"padding: 5px; font-weight: bold; text-align: center; font-size: 20px;\">";
            strEmail = strEmail + "<div style=\"background-image: url(http://abc.com/images/servicedesc.png);";
            strEmail = strEmail + "width: 260px; height: 189px;\">";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "<td width=\"70%\" style=\"padding: 5px; font-weight: bold; text-align: left;\" style=\"background-image: url(http://abc.com/images/background.png);";
            strEmail = strEmail + "width: 630px; height: 149px; vertical-align: middle;\">";
            strEmail = strEmail + "<div style=\"line-height: 1.5em; font-weight: bolder; font-size: 24px; font-family: Tahoma;\">";
            strEmail = strEmail + "&nbsp;. Service Type: Standard";
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "&nbsp;. Carrier:" + carrierType;
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td>";
            strEmail = strEmail + "&nbsp";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td width=\"30%\" style=\"padding: 5px; font-weight: bold; text-align: center; font-size: 20px;\">";
            strEmail = strEmail + "<div style=\"background-image: url(http://abc.com/images/price.png); width: 249px;";
            strEmail = strEmail + "height: 189px;\">";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "<td width=\"70%\" style=\"padding: 5px; font-weight: bold; text-align: left; font-size: 20px\"";
            strEmail = strEmail + "style=\"background-image: url(http://abc.com/images/background.png);";
            strEmail = strEmail + "width: 630px; height: 149px; vertical-align: middle;\">";
            strEmail = strEmail + "<div style=\"line-height: 1.5em; font-weight: bolder; font-size: 24px; font-family: Tahoma;\">";
            strEmail = strEmail + "<div style=\"font-family: Verdana; font-weight: bolder; padding: 5px; text-align: left;";
            strEmail = strEmail + "vertical-align: top;\">";
            strEmail = strEmail + ". Discounted Price: $" + deposit;
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "&nbsp;. Deposit, Taxes & Fuel charges:Already included.";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "</table>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\">";
            strEmail = strEmail + "&nbsp;";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\">";
            strEmail = strEmail + "<h1>";
            strEmail = strEmail + "Important Quote Details:";
            strEmail = strEmail + "</h1>";
            strEmail = strEmail + "<div style=\"font-size: 22px; font-family: Tahoma; font-weight: bolder; padding: 5px;";
            strEmail = strEmail + "text-align: left; line-height: 2em;\">";
            strEmail = strEmail + "- The quote is for a door to door service, direct non stop one truck transport,";
            strEmail = strEmail + "with full coverage insuance, order tracking, and all taxes and fees.";
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "- Prices may vary due to seasonal changes, so call now to make your reservation.";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\">";
            strEmail = strEmail + "&nbsp;";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\" align=\"center\">";
            strEmail = strEmail + "<div style=\"background-image: url(http://abc.com/images/emailmehndibackground.png);";
            strEmail = strEmail + "width: 750px; height: 81px; color: White; font-size: 36px; vertical-align: middle;\">";
            strEmail = strEmail + "Contact us to Make your Reservation";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\" align=\"center\">";
            strEmail = strEmail + "<h2>";
            strEmail = strEmail + "&nbsp;</h2>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\" align=\"left\">";
            strEmail = strEmail + "<h1>";
            strEmail = strEmail + fromName;
            strEmail = strEmail + "</h1>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\" align=\"left\" style=\"color: Black;text-decoration: underline;\">";
            strEmail = strEmail + "<h1>";
            strEmail = strEmail + fromEmail;
            strEmail = strEmail + "</h1>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\" align=\"left\">";
            strEmail = strEmail + "<h1>";
            strEmail = strEmail + "(1) 347-901-4509 Ext 301";
            strEmail = strEmail + "</h1>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\" align=\"left\">";
            strEmail = strEmail + "<h1>";
            strEmail = strEmail + "(1) 347-750-0857 Fax";
            strEmail = strEmail + "</h1>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\" align=\"left\">";
            strEmail = strEmail + "&nbsp;";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\" align=\"center\" style=\"background-image: url(http://abc.com/images/emailshadedGreen.png);";
            strEmail = strEmail + "background-repeat: repeat-x; padding-bottom: 20px; padding-top: 20px;\">";
            strEmail = strEmail + "<div style=\"color: White;\">";
            strEmail = strEmail + "<h1>";
            strEmail = strEmail + "For more information visit our website";
            strEmail = strEmail + "</h1>";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "<div style=\"text-decoration: underline;\">";
            strEmail = strEmail + "<h1>";
            strEmail = strEmail + "<a href=\"http://www.thewaymovers.com/" style=\"color: Black; text-decoration: underline;";
            strEmail = strEmail + "font-family: Verdana;\">www.thewaymovers.com</a>";
            strEmail = strEmail + "</h1>";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\">";
            strEmail = strEmail + "<hr />";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\">";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "<tr>";
            strEmail = strEmail + "<td colspan=\"2\">";
            strEmail = strEmail + "<h1>";
            strEmail = strEmail + "You can also request for special services such as:";
            strEmail = strEmail + "</h1>";
            strEmail = strEmail + "<div style=\"font-size: 22px; font-family: Tahoma; font-weight: bolder; padding: 5px;";
            strEmail = strEmail + "text-align: left; line-height: 2em;\">";
            strEmail = strEmail + "- Expedited 24 to 48 hours guaranteed pickup<br />";
            strEmail = strEmail + "- Priority pickup guaranteed within 5 business days.";
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "- Military discounts.";
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "- Referral discounts";
            strEmail = strEmail + "<br />";
            strEmail = strEmail + "</div>";
            strEmail = strEmail + "</td>";
            strEmail = strEmail + "</tr>";
            strEmail = strEmail + "</table>";
            strEmail = strEmail + "</body>";
            strEmail = strEmail + "</html>";

            return strEmail;
        }

It looks like the method you have posted is generating the Body of the email.

[)ia6l0 iii replied to asif hameed on 10-Jan-10 06:19 AM
The mail could be rejected by the server of your recepient for the following reasons. 
a) The links in the email messages. (Phishing filters?)
b) Length of the message.
c) Some times , the images that you have in your html, that are from unknown domain do not make it through the filters on few servers. 

Did you try a plain text message?

Since you have posted your entire email body for reference, there could be someone else who would take a deeper look and come out with something else. 

So meanwhile, check for the points I mentioned above.

Re - Huggy Bear replied to asif hameed on 11-Jan-10 01:12 AM

This should be because you are trying to attach a virus infected file to the email or the email message's content image urls are considered to be phishing links. Check for the appropriate case.

error in sending email - mv ark replied to asif hameed on 11-Jan-10 10:02 AM

By avoiding "spammy" text in the email, fewer images, a good well formed layout and having both HTML  and plain text views of the message, you can prevent an email from being marked as spam by spam filters.

Check this article & the C# code sample in it for creating an AlternateView that will please the spam filter - http://www.andreas-kraus.net/blog/tips-for-avoiding-spam-filters-with-systemnetmail/

Also check this - http://mvark.blogspot.com/2008/12/how-to-avoid-spam-filters-while.html