I'm putting together a script to send out a preview html mail to hotmail etc, and I utlising an existing script - I'm new to c# so this is as much a learning expereince forme too.
The problem is I have made a few ammends, and it's fine up to the point I drop 开发者_运维技巧HTML source into the comments box - it then fails the sending.
I have looked into it and tried changing the new MailMessage(); to new MailDefinition(); and also adding in faqMsg.IsBodyHtml = true; but it's still failing. it's fine just on regular text. Any thoughts what I need to look into ?
SmtpClient smtpCli = new SmtpClient("localhost");
MailMessage faqMsg = new MailMessage();
//MailDefinition faqMsg = new MailDefinition();
//faqMsg.BodyFileName = "email.htm";
//faqMsg.IsBodyHtml = true;
faqMsg.From = new MailAddress("");
faqMsg.To.Add("");
faqMsg.Subject = "Mail test :" + subject.Text;
//Plain Text part
AlternateView plainView = AlternateView.CreateAlternateViewFromString("Enquiry Type:" + enquirytype.SelectedValue + "\r\nFrom:" + "\r\nEmail:" + email.Text + "\r\n\r\nComments\r\n" + comments.Text + "\r\n[EOF]", null, "text/plain");
//HTML part
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<strong>Enquiry Type:</strong>" + enquirytype.SelectedValue + "<br><br><strong>Email:</strong>" + email.Text + "<br><br><hr><br><strong>Comments</strong><br>" + HttpUtility.HtmlEncode(comments.Text) + "<br>EOF", null, "text/html");
faqMsg.AlternateViews.Add(plainView);
faqMsg.AlternateViews.Add(htmlView);
//Add Header Markers
faqMsg.Headers.Add("X-Company", "");
faqMsg.Headers.Add("X-Location", "");
faqMsg.Headers.Add("X-Brand", "");
smtpCli.Send(faqMsg);
lbReport.Text = "Your Message was Sent";
//Response.Redirect("email-thanks.aspx");
Hey, what error are you getting?
Looking at the code, you may need to add an @ symbol before any strings with the \ inside. But that's a guess without the error.
Without the exact exception text you are seeing, Im going to take a stab at this.
This doesn't sound like an email error.
this sounds like the generic error that won't allow you to enter HTML content into a textbox.
Be sure VaildateRequest=false
in the @Page
attribute at the top of the page.
精彩评论