Sending Mail with an attachment using SMTP
<pre><code>protected void Button1_Click(object sender, EventArgs e)
{
    var fromAddress = new MailAddress(fromid.Text, fromname.Text);
    var toAddress = new MailAddress(toid.Text, toname.Text);
    string fromPassword = pswd.Text;
    string subject = subjectbox.Text;
     string body = bodybox.Text;
     Attachment at = new Attachment(Server.MapPath("~/Penguins.jpg"));

    var smtp = new SmtpClient
    {
        Host = "smtp.gmail.com",
        Port = 587,
        EnableSsl = true,
        DeliveryMethod = SmtpDeliveryMethod.Network,
        Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
        Timeout = 20000,

    };
    using (var message = new MailMessage(fromAddress, toAddress)
    {
        Subject = subject,
        Body = body,
        IsBodyHtml = false,


    })
    {
        message.Attachments.Add(at);
        smtp.Send(message);
    }

}
</code></pre>

<p>There is no error but while sending mail it takes some time and shows "Connection TimeOut" and not sending mail...:(
Can any one tell where is the problem. </p>
