Hi Everyone,
I am sending mail using the code provided by Chilkat.inc.
Here if i attach the file by giving direct path files are attaching that means
files are attaching with this code "contentType = email.AddFileAttachment(@"E:\Test.mp3");" not with this
"contentType = Server.MapPath("~/Enclosure/") + lstUpload.Items[i].Text;".
Please help me to sort out this
Regards
Nanda
Here is my code:
bool success;
Chilkat.MailMan mailman = new Chilkat.MailMan();
mailman.UnlockComponent("30-day trial");
Chilkat.Email email = new Chilkat.Email();
mailman.SmtpHost = "smtp.gmail.com";
mailman.SmtpPort = 587;
mailman.SmtpUsername = "gmail.com";
mailman.SmtpPassword = "password";
mailman.SmtpSsl = true;
email.Body = "This is the plain-text alternative";
email.AddHtmlAlternativeBody("<html><body><font color="red" size="+1">This is bold red text.</font></html>");
email.Subject = "This email has a file attachment.";
email.AddTo("Chilkat Support", "nanda2607@gmail.com");
email.From = "gmail.com";
string contentType;
string docfile = "";
ArrayList al = new ArrayList();
for (int i = 0; i < lstUpload.Items.Count; i++)
{
contentType = Server.MapPath("~/Enclosure/") + lstUpload.Items[i].Text;
al.Add(contentType);
}
if (txtfile.Text != "")
{
docfile = Server.MapPath("~/Templates/") + txtfile.Text;
}
success = mailman.SendEmail(email);
if (success)
{
ScriptManager.RegisterStartupScript(this, typeof(string), "openNewWindow", "<script>alert('Email Sent Successfully')</script>", false);
if (lstUpload.Items.Count > 0)
{
for (int i = 0; i < lstUpload.Items.Count; i++)
{
SqlCommand cmd = new SqlCommand("spInsertTblEnclosureFiles");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@colname", SqlDbType.VarChar).Value = "finalspecno";
cmd.Parameters.Add("no", SqlDbType.Int).Value = ddlfinalspec.SelectedValue;
cmd.Parameters.Add("@companyid", SqlDbType.Int).Value = Convert.ToInt16(Session["companyid"]);
cmd.Parameters.Add("filename", SqlDbType.VarChar).Value = lstUpload.Items[i].Text;
int stchng = ems.Execute_Sql(cmd, con);
}
}
}
else
{
string str = "Email Not Send Successfully";
lblMsg.Text = str;
}
[edit]Code block added - OriginalGriff[/edit]