Avatar of nirisan
nirisan

asked on 

How do i add multiple attachments to my email webservice so that users can consume to send multiple attachments using C#

Im using the System.Net.mail namespace and am creating a webservice to send emails.

i would like to add a webmethod where a collection of attachments could be added to the email. There are many examples with single attachement.

Please suggest with code. Below is my class for sending the email which i call in the webservice.
MailAddress from = new MailAddress(From);
            MailAddress to = new MailAddress(To);
            MailMessage mail = new MailMessage(from , to);
            if (Cc.Length > 0)
            {
                MailAddress copy = new MailAddress(Cc);
                mail.CC.Add(copy);
            }
            if (Bcc.Length > 0)
            {
                MailAddress bcopy = new MailAddress(Bcc);
 
                mail.Bcc.Add(bcopy);
            }
            if (Subject.Length > 0)
            {
                mail.Subject = Subject;
            }
            if (Body.Length > 0)
            {
                mail.Body = Body;
            }
            mail.IsBodyHtml = true;
            
 
                
                //Send the message.
                SmtpClient client = new SmtpClient(GetSmtpServer());
                client.Send(mail);
}

Open in new window

C#

Avatar of undefined
Last Comment
navyjax2
ASKER CERTIFIED SOLUTION
Avatar of joesthebighmoe
joesthebighmoe
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of navyjax2
navyjax2

C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo