Tuesday 25 December 2012

Email Sending with Multiple Attachments

Using System.Net.Mail namespace u can send mails.


Here is a code for this. You can use the same code to create a method with the parameters (specified variables) and call from any places.
The Mail ids, attachments are separated with comma (,).


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string SmtpServer = ConfigurationManager.AppSettings["App_Mail_Server"]; // Provide the SMTP server name
            string strFrom = "abc@xyz.com";
            string strTo = "cde@pqr.com,cde1@pqr1.com";
            string strCC = "cde2@pqr4.com,cde3@pqr5.com";
            string strBCC = "cde5@pqr3.com,cdew@pqrw.com";
            string strPeriority = "High";
            string strAttachment = @"C:\parent screen.jpg,C:\Print Screen.jpg";
            string strSubject = "Test Mail with Multiple Attachment";
            string strBody = "Test Mail with Multiple Attachment";
            bool IsBodyIsInHTML = false;


            try
            {
                SmtpClient smtp = new SmtpClient(SmtpServer);
                MailMessage mssg = new MailMessage();
                mssg.From = new MailAddress(strFrom);
                mssg.Subject = strSubject;
                mssg.Body = strBody;


                //Adding multiple To Addresses
                foreach (string sTo in strTo.Split(",".ToCharArray()))
                    mssg.To.Add(sTo);


                //Adding multiple CC Addresses
                foreach (string sCC in strCC.Split(",".ToCharArray()))
                    mssg.CC.Add(sCC);


                //Adding multiple BCC Addresses
                foreach (string sBCC in strBCC.Split(",".ToCharArray()))
                    mssg.Bcc.Add(sBCC);


                //Adding multiple BCC Addresses
                foreach (string sAttachment in strAttachment.Split(",".ToCharArray()))
                {
                    Attachment attachment = new Attachment(sAttachment);
                    mssg.Attachments.Add(attachment);
                }


                MailPriority mailPeriority = MailPriority.Normal;
                switch (strPeriority)
                {
                    case "High":
                        mailPeriority = MailPriority.High;
                        break;
                    case "Low":
                        mailPeriority = MailPriority.Low;
                        break;
                    case "Normal":
                        mailPeriority = MailPriority.Normal;
                        break;
                }
                mssg.Priority = mailPeriority;


                mssg.BodyEncoding = System.Text.Encoding.Default;
                mssg.SubjectEncoding = System.Text.Encoding.Default;
                mssg.IsBodyHtml = IsBodyIsInHTML;
                smtp.Send(mssg);
            }
            catch (Exception ex)
            {
                //trach the exception and write in the log. might be Main Addresses contains non mail id formats.
            }


        }
    }
}


51 comments:

  1. For email attachment size problems, Thru offers an enterprise solution to securely and effortlessly send these files, without any change in workflow.
    You should check it out. Thru offers a great solution for email attachment managemnt.

    http://www.thruinc.com/email-attachment-management/

    ReplyDelete
  2. Your source on Email Sending with Multiple Attachments is working great.

    ReplyDelete
  3. Wow! That's really great information guys.I know lot of new things here. Really great contribution.Thank you ...
    java training in chennai

    ReplyDelete
  4. Thanks for sharing this informative blog. Keep update your blog.
    J2EE training in chennai

    ReplyDelete
  5. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    Best selenium training Institute in chennai

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This is a nice post in an interesting line of content.Thanks for sharing this article, great way of bring this topic to discussion.
    java training in annanagar | java training in chennai

    java training in marathahalli | java training in btm layout

    java training in rajaji nagar | java training in jayanagar

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. This is very good content you share on this blog. it's very informative and provide me future related information.

    angularjs-Training in velachery

    angularjs-Training in annanagar

    angularjs Training in chennai

    angularjs Training in chennai

    ReplyDelete
  10. All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
    python online training
    python training course in chennai
    python training in jayanagar

    ReplyDelete
  11. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...


    Selenium online Training | Selenium Training in Pune | Selenium Training in Bangalore

    ReplyDelete
  12. You know what you’re talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?
    safety course in chennai

    ReplyDelete
  13. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in chennai

    automation anywhere online Training

    ReplyDelete
  14. Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your blog? My blog is in the same niche as yours, and my users would benefit from some of the information you provide here. Please let me know if this ok with you. Thank you.
    fire and safety course in chennai

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. It is a great post. Keep sharing such kind of useful information.

    englishlabs
    Guest posting sites

    ReplyDelete
  17. A good blog for the people who really needs information about this. Good work keep it up.

    Article submission sites
    Guest posting sites

    ReplyDelete
  18. Nice Post! Thank you for sharing knowledge, it was very good post to update my knowledge and improve my skills. keep blogging.
    Java Training in Electronic City

    ReplyDelete
  19. Merely a smiling visitant here to share the love (:, btw outstanding style. find personal email

    ReplyDelete
  20. Heyy! Checkout Our Reliable SMPP server platform is which specially designed for high-volume Bulk sms users.

    ReplyDelete
  21. Hi,
    Good job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take python training in bangalore. Because Python course in Bangalore is one of the best that one can do while choosing the course.

    ReplyDelete
  22. I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing. Great efforts.

    Looking for Training Institute in Bangalore , India. Softgen Infotech is the best one to offers 85+ computer training courses including IT software course in Bangalore, India. Also it provides placement assistance service in Bangalore for IT.
    Best Software Training Institute in Bangalore

    ReplyDelete
  23. I am really happy to say it’s an interesting post to read. I learn new information from your article; you are doing a great job. Keep it up

    Learn Hadoop Training from the Industry Experts we bridge the gap between the need of the industry. Softgen Infotech provide the Best Hadoop Training in Bangalore with 100% Placement Assistance. Book a Free Demo Today.
    Big Data Analytics Training in Bangalore
    Tableau Training in Bangalore
    Data Science Training in Bangalore
    Workday Training in Bangalore

    ReplyDelete
  24. wondering information's about Studies and getting new innovative ideas Through this articles.Thanks for sharing your valuable Information's.
    python training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery

    ReplyDelete
  25. I would like to say thank you for the amazing details and concepts you are sharing in this.The style of writing is excellent and also the content is top-notch.




    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery




    ReplyDelete
  26. Its is very helpful for all of us and I never get bored while reading your article
    because, they are becomes a more and more interesting from the starting lines until the end.it is an awesome article i can learn more about devops. the way of presentation was so good
    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training

    ReplyDelete
  27. Hi nice post one of the best blog to share here thank you for this blog

    AI Training in Hyderabad

    ReplyDelete
  28. Sharing the same interest, Infycle feels so happy to share our detailed information about all these courses with you all! Do check them out
    oracle training in chennai & get to know everything you want to about software trainings.

    ReplyDelete
  29. Study Amazon Web Services for making your career as a shining sun with Infycle Technologies. Infycle Technologies is the best AWS training institute in Chennai, providing complete hands-on practical training of professional specialists in the field. In addition to that, it also offers numerous programming language tutors in the software industry such as Oracle, Python, Big Dat, Hadoop, etc. Once after the training, interviews will be arranged for the candidates, so that, they can set their career without any struggle. Of all that, 200% placement assurance will be given here. To have the best career, call 7502633633 to Infycle Technologies and grab a free demo to know more.
    TOP AWS TRAINING IN CHENNAI

    ReplyDelete
  30. Extremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. A debt of gratitude is in order for sharing.360digitmg-data science course data science course in mysore

    ReplyDelete
  31. Любой жаждет узнать свое будущее и воспринимает конкретные средства хиромантии более достоверными. Гадание на три карты это попытка предсказать грядущие действия постоянно завлекал человека. Предсказание будущего дозволяет просмотреть, что человека ожидает в предстоящем времени.

    ReplyDelete
  32. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.data science course data science course in surat

    ReplyDelete
  33. I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.data science course data science course in mysore

    ReplyDelete
  34. Here at this site is really a fastidious material collection so that everybody can enjoy a lot.
    data analytics training in hyderabad

    ReplyDelete

If any doubt?then please comment in my post

How to reduce angular CLI build time

 Index: ----- I am using angular cli - 7 and I am going to tell how to reduce the build time as per my knowledge. Problem: -------- Now the ...