Asp email submission with file attachment
<p>I have the following code but it does not work - I get errors when using a <code>message.To</code> then I changed it to <code>message.To.Add</code> but without any success.</p>

<p>I don't know ASP.net, I just want this thing to work. Any help is appreciated.</p>

<pre><code>using System.Net.Mail;


protected void btnsubmit_Click(object sender, EventArgs e)
{
    string body = "";
    string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
    body = "&lt;table border='0' align='center' cellpadding='2' style='border-collapse: collapse' bordercolor=''#111111' width='100%' id='AutoNumber1'&gt;";
    body = body + "&lt;tr&gt;&lt;td width='100%' align='center' colspan='6'&gt;&lt;b&gt;Photo Submission Form&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;";
    body = body + "&lt;tr&gt;&lt;td width='100%' colspan='6'&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;";
    body = body + "&lt;tr&gt;&lt;td width='50%' colspan='2'&gt;Name&lt;/td&gt;&lt;td width='50%' colspan='4'&gt;&lt;b&gt;" + name.Text + "&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;";
    body = body + "&lt;tr&gt;&lt;td width='50%' colspan='2'&gt;E-Mail&lt;/td&gt;&lt;td width='50%' colspan='4'&gt;&lt;b&gt;" + email.Text + "&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;";
    body = body + "&lt;tr&gt;&lt;td width='50%' colspan='2'&gt;Caption&lt;/td&gt;&lt;td width='50%' colspan='4'&gt;&lt;b&gt;" + caption.Text + "&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;";
    body = body + "&lt;tr&gt;&lt;td width='50%' colspan='2'&gt;Phone&lt;/td&gt;&lt;td width='50%' colspan='4'&gt;&lt;b&gt;" + phone.Text + "&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;";
    MailMessage message = new MailMessage();
    Attachment myAttachment = new Attachment(FileUpload1.FileContent, fileName);
    message.To.Add(new MailAddress("contact@xxxx.com"));
    message.From = New MailAddress(email.Text);
    message.Subject = "Photo Submission Form";
    message.BodyFormat = MailFormat.Html;
    message.Body = body;
    message.Attachments.Add(myAttachment);
    SmtpMail.SmtpServer.Insert(0, "");
    SmtpMail.Send(message);
    RegisterStartupScript("startupScript", "&lt;script language=JavaScript&gt;alert('Message sent successfully.');&lt;/script&gt;");
</code></pre>
