#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2014
    Location
    Kolkata, India
    Posts
    4
    Rep Power
    0

    Post I cant send mails with attachments in Dot Net, its goes to catch part


    Hello,

    I cant send mails with attachments in Dot Net, its goes to catch part whenever it reaches the line

    <%@ Attachment at = new Attachment(filepath); %>

    After executing this line it jumps to catch part, I dont know why. Here is my code

    Code:
    <%@
                try
                {
                    if (FileUpload1.HasFile)
                    {
                        filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
                        FileUpload1.SaveAs(Server.MapPath("../images/temp_uploads/" + FileUpload1.FileName));
                        filepath = "http://localhost:2986/Website/images/temp_uploads/" + filename;
                    }
    
    
                        MailAddress SendFrom = new MailAddress("sales@xyz.com");
                        MailAddress SendTo = new MailAddress(emailTo);
    
                        MailMessage MyMessage = new MailMessage(SendFrom, SendTo);
    
                        MyMessage.Subject = txtSubject.Text;
                        MyMessage.Body = txtBody.Text;
                        MyMessage.IsBodyHtml = true;
    
                        if (FileUpload1.HasFile)
                        {
                            Attachment at = new Attachment(filepath);
                            MyMessage.Attachments.Add(at);
                            MyMessage.Priority = System.Net.Mail.MailPriority.High;
                        }
    
                        SmtpClient emailClient = new SmtpClient("xyz.com");
                        emailClient.Send(MyMessage);
                        MyMessage.Dispose();
               }
               catch (Exception ex)
                {
                    litStatus.Text = "*Sending Failed!";
                }
    %>
  2. #2
  3. Forgotten Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,090
    Rep Power
    9644
    That Exception would have told you what went wrong. You should look at its message, perhaps by including it in the litStatus text...

IMN logo majestic logo threadwatch logo seochat tools logo