Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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:


C#
bool success;

// Create a mailman object for sending email.
Chilkat.MailMan mailman = new Chilkat.MailMan();

// Any string argument automatically begins the 30-day trial.
mailman.UnlockComponent("30-day trial");

// Set the SMTP server host.
//mailman.SmtpHost = "smtp.gmail.net";

// Create a simple email with several file attachments.
Chilkat.Email email = new Chilkat.Email();
mailman.SmtpHost = "smtp.gmail.com";

mailman.SmtpPort = 587;
mailman.SmtpUsername = "gmail.com";
mailman.SmtpPassword = "password";
mailman.SmtpSsl = true;

// This email will have both a plain-text body and an HTML body.
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";

// Add a file attachment.
string contentType;
// Returns the content-type of the attachment (determined by the file extension)
// This return value is for informational purposes only.




string docfile = "";
ArrayList al = new ArrayList();
for (int i = 0; i < lstUpload.Items.Count; i++)
{
   // contentType = email.AddFileAttachment(@"E:\Test.mp3");

    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]
Posted
Updated 16-Oct-12 1:16am
v4
Comments
Richard MacCutchan 16-Oct-12 7:44am    
You will probably get a faster response by asking at Chilkat.
[no name] 16-Oct-12 8:51am    
Try using cmd.Parameters.AddWithValue instead.
ZurdoDev 16-Oct-12 10:18am    
What's the problem exactly? What's the error? Is the file you want to attach in your website folder structure?
Member 9345484 16-Oct-12 12:31pm    
yes i want to attach files..... no error.....

If you are having a problem using their product, perhaps you should ask them directly for an answer: Vendor[^]
 
Share this answer
 
Oh no! I do not believe that it works when you use the simple path. No! You create an Arraylist, add the path to it. And then? Nowhere gets that Arraylist connected to the mail...
Also docfile does not at all find its way into the email.
 
Share this answer
 
Comments
Member 9345484 17-Oct-12 4:16am    
Bernhard i posted this hurry but in my project i kept path out side the arraylist so direct path is working fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900