Exemplo n.º 1
0
        static void send(string subject, User to)
        {
            try
            {
                MailBuilder builder = new MailBuilder();
                builder.Html    = @"Html with an image: <img src=""cid:lena"" />";
                builder.Subject = subject;


                MimeData visual = builder.AddVisual(HostingEnvironment.MapPath("~/Images/logo_2.png"));
                visual.ContentId = "lena";

                MimeData attachment = builder.AddAttachment(@"C:\Users\User\Desktop\Attachment.txt");
                attachment.FileName = "document.doc";

                builder.From.Add(new MailBox("*****@*****.**"));
                builder.To.Add(new MailBox(to.Email));
                //builder.To.Add(new MailBox("*****@*****.**"));
                IMail email = builder.Create();

                using (Smtp smtp = new Smtp())
                {
                    smtp.Connect(_server);       // or ConnectSSL for SSL
                    smtp.UseBestLogin(_user, _password);

                    smtp.SendMessage(email);

                    smtp.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }