views:

609

answers:

1

I have a script that sends an e-mail as both plain text and HTML, and it works fine for most e-mail readers including Outlook and Gmail. However, when reading the message on a Windows Mobile smartphone, the output is:

PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDMuMiBGaW5hbC8vRU4i Pg0KPEhUTUw+DQo8SEVBRD4NCiAgICA8TUVUQSBIVFRQLUVRVUlWPSJDb250ZW50LVR5cGUi IENPTlRFTlQ9InRleHQvaHRtbDtjaGFyc2V0PWlzby04ODU5LTEiPg0KICAgIDxUSVRMRT5Z b3VyIE1lZ2Fwb255IFBhc3N3b3JkIC0gTWVnYXBvbnkgLSBEaXNjb3ZlciB0aGUgbmV4dCBi aWcgdGhpbmc8L1RJVExFPg0KICAgIDxTVFlMRSBUWVBFPSJ0ZXh0L2NzcyI+DQogICAgICAg IGE6bGluaywgYTp2aXNpdGVkDQogICAgICAgIHsNCiAgICAgICAgICAgIHRleHQtZGVjb3Jh dGlvbjogdW5kZXJsaW5lOw0KICAgICAgICAgICAgY29sb3I6ICM5MDA7DQogICAgICAgIH0N CiAgICAgICAgYTpob3Zlcg0KICAgICAgICB7DQogICAgICAgICAgICB0ZXh0LWRlY29yYXRp b246IG5vbmU7DQogICAgICAgICAgICBjb2xvcjogIzAwMDsNCiAgICAgICAgfQ0KICAgIDwv U1RZTEU+DQo8L0hFQUQ+DQo8Qk9EWT4NCiAgICA8QSBIUkVGPSJodHRwOi8vd3d3Lm1lZ2Fw b255LmNvbS8iIFRJVExFPSJNZWdhcG9ueSAtIERpc2NvdmVyIHRoZSBuZXh0IGJpZyB0aGlu ZyI+DQogICAgICAgIDxJTUcgU1JDPSJodHRwOi8vd3d3Lm1lZ2Fwb255LmNvbS9faW1nL21l Z2Fwb255LWhlYWRlci1yZWQuZ2lmIiBXSURUSD0iNjMwIiBIRUlHSFQ9Ijg4IiBBTFQ9Ik1l Z2Fwb255IC0gRGlzY292ZXIgdGhlIG5leHQgYmlnIHRoaW5nIg0KICAgICAgICAgICAgQk9S REVSPSIwIj48L0E+DQogICAgPEZPTlQgU0laRT0iNCIgRkFDRT0iQXJpYWwiPg0KICAgIDxC Uj4NCiAgICA8QlI+DQogICAgWW91ciBNZWdhcG9ueSBwYXNzd29yZCBpczoNCiAgICAgICAg PEJSPg0KICAgICAgICA8QlI+DQogICAgICAgIEt1YnkyNDI0DQogICAgICAgIDxCUj4NCiAg ICAgICAgPEJSPg0KICAgICAgICBHbyB0byANCiAgICA8L0ZPTlQ+DQogICAgPEEgSFJFRj0i aHR0cDovL3d3dy5tZWdhcG9ueS5jb20vIiBUSVRMRT0iTWVnYXBvbnkgLSBEaXNjb3ZlciB0 aGUgbmV4dCBiaWcgdGhpbmciPg0KICAgICAgICA8Rk9OVCBTSVpFPSI0IiBGQUNFPSJBcmlh bCIgQ09MT1I9IiM5OTAwMDAiPk1lZ2Fwb255LmNvbTwvRk9OVD48L0E+DQogICAgICAgIDxG T05UIFNJWkU9IjQiIEZBQ0U9IkFyaWFsIj4NCiAgICAgICAgICAgIHRvIGFjY2VzcyB5b3Vy IGFjY291bnQuDQogICAgICAgICAgICA8QlI+DQogICAgICAgICAgICA8QlI+DQogICAgICAg ICAgICBUaGFuayB5b3UgZm9yIHlvdXIgc3VwcG9ydCBvZiBNZWdhcG9ueSBhbmQgaW5kZXBl bmRlbnQgbXVzaWMhPEJSPg0KICAgICAgICAgICAgPEJSPg0KICAgICAgICAgICAgU2luY2Vy ZWx5LDxCUj4NCiAgICAgICAgICAgIDxCUj4NCiAgICAgICAgICAgIFRoZSBNZWdhcG9ueSBU ZWFtPEJSPg0KICAgICAgICAgICAgPEJSPg0KICAgICAgICAgICAgPEJSPg0KICAgICAgICA8 L0ZPTlQ+PEZPTlQgU0laRT0iMiIgRkFDRT0iQXJpYWwiPipUaGlzIGlzIGFuIGF1dG9tYXRl ZCBtZXNzYWdlLiBQbGVhc2UgZG8gbm90IHJlcGx5LjwvRk9OVD4NCjwvQk9EWT4NCjwvSFRN TD4NCg==

The correct output should be: Click here to see

The code is:

SmtpClient mC = new SmtpClient(ConfigurationManager.AppSettings["smtpServer"]);
        NetworkCredential nC = new NetworkCredential(ConfigurationManager.AppSettings["smtpUsername"], ConfigurationManager.AppSettings["smtpPassword"]);
        mC.UseDefaultCredentials = false;
        mC.Credentials = nC;
        MailAddress mFrom = new MailAddress("[email protected]", "Megapony");
        MailAddress mTo = new MailAddress(forgotpwemail.Text);

        MailMessage mMsg = new MailMessage(mFrom, mTo);


        mMsg.IsBodyHtml = false;
        mMsg.Subject = "Your Megapony Password";

        mMsg.Body = getForgotPWBodyPlain(result);

        System.Net.Mime.ContentType mimeType = new System.Net.Mime.ContentType("text/html");



        AlternateView alternate = AlternateView.CreateAlternateViewFromString(getForgotPWBody(result), mimeType);

        mMsg.AlternateViews.Add(alternate);

        try
        {

            mC.Send(mMsg);
            pnlpwform.Visible = false;
            pnlSuccess.Visible = true;

        }
        catch (Exception)
        {
            pnlResponse.Visible = true;
        }
        mMsg.Dispose();

Please help!

Thanks, Paul

+2  A: 

I would say it's a combination of the content-type and the the image that's causing the issue. The link you provided showed a nice gif with a Megapony logo, yet the content-type is set to text only. Because of this, the bits that make up the gif is being treated as a series of text characters.

This would be a good place to start: http://www.systemnetmail.com/faq/3.1.3.aspx

David Stratton
If feasible, you may want to just have an external link to the image in your HTML rather than embedding the image directly in the email. Your current strategy for sending mail could result in a lot of unnecessary bandwidth usage for your SMTP server, especially if you're paying a third party service for it.
Alex Marshall