Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi everyone, I'm sending reports via Email automatically from application to clients using code (found on this web) but antivirus of client is detecting attachment (Report in PDF) as virus and is deleting it. could anybody help me how to prevent t without stopping client antivirus.

C#
SmtpClient SmtpServer = new SmtpClient();
           SmtpServer.Credentials = new    

  System.Net.NetworkCredential("info9@gmail.com", "********");
            SmtpServer.Port = 587;
            SmtpServer.Host = "smtp.gmail.com";
            SmtpServer.EnableSsl = true;
            mail = new MailMessage();
            String[] addr = TextBox1.Text.Split(',');
            try 
            {
                mail.From = new MailAddress("info9@gmail.com", "So and So", System.Text.Encoding.UTF8);
                Byte i;
                for( i = 0;i< addr.Length; i++)
                    mail.To.Add(addr[i]);
                mail.Subject = TextBox3.Text;
                mail.Body = TextBox4.Text;
                if(ListBox1.Items.Count != 0)
                {
                    for(i = 0;i<ListBox1.Items.Count;i++)
                    mail.Attachments.Add(new Attachment(ListBox1.Items[i].ToString()));
                }
                LinkedResource logo = new LinkedResource(path);
                logo.ContentId = "Logo";
                string htmlview;
                htmlview = "<html><body><table border=2><tr width=100%><td><img src=cid:Logo alt=companyname /></td><td>MY COMPANY DESCRIPTION</td></tr></table><hr/></body></html>";
                AlternateView alternateView1 = AlternateView.CreateAlternateViewFromString(htmlview + TextBox4.Text, null, MediaTypeNames.Text.Html);
                alternateView1.LinkedResources.Add(logo);
                mail.AlternateViews.Add(alternateView1);
                mail.IsBodyHtml = true;
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                mail.ReplyTo = new MailAddress(TextBox1.Text);
                SmtpServer.Send(mail);
            }
            catch (Exception ex){
            MessageBox.Show(ex.ToString());
            }
Posted
Updated 19-Jan-12 12:24pm
v2

1 solution

Well, you cannot predict how crazy every particular anti-virus could go. One practical advice would be to zip all the files to be added as attachment (only if you can), but this won't really guarantee that the attachment is not removed by the antivirus. Antivirus tools used at the level of e-mail sometimes do idiotic things, it also depends on policy options applied on a particular host.

—SA
 
Share this answer
 
v2
Comments
Wonde Tadesse 19-Jan-12 19:06pm    
5+. Makes sense.
Sergey Alexandrovich Kryukov 19-Jan-12 19:21pm    
Thank you, Wonde.
--SA
Valdet Zabeli 20-Jan-12 4:39am    
U'r Right but it is interesting that if i attach that file normally (not using code), it doesn't delete the file

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