当前位置: 首页>>代码示例>>C#>>正文


C# Mail.Attachment类代码示例

本文整理汇总了C#中System.Net.Mail.Attachment的典型用法代码示例。如果您正苦于以下问题:C# Attachment类的具体用法?C# Attachment怎么用?C# Attachment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Attachment类属于System.Net.Mail命名空间,在下文中一共展示了Attachment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendMail

        public static void SendMail(IEmailAccountSettingsProvider provider, string to, string subject, string body, Attachment attach, AlternateView av, bool isHTML)
        {
            if (provider.SmtpFrom != String.Empty)
            {
                if (provider.SmtpHost == "") return;
                MailMessage mailMessage = new MailMessage();
                mailMessage.From = new MailAddress(provider.SmtpFrom);
                mailMessage.To.Add(to);
                mailMessage.Subject = subject;
                if (av != null)
                    mailMessage.AlternateViews.Add(av);
                mailMessage.BodyEncoding = Encoding.UTF8;
                mailMessage.Body = body;

                if (attach != null)
                    mailMessage.Attachments.Add(attach);
                if (isHTML)
                    mailMessage.IsBodyHtml = true;

                SmtpClient smtpClient = new SmtpClient();
                smtpClient.Host = provider.SmtpHost;
                smtpClient.Port = Convert.ToInt32(provider.SmtpPort);
                smtpClient.UseDefaultCredentials = Convert.ToBoolean(provider.SmtpCredentials);
                smtpClient.Credentials = new NetworkCredential(provider.SmtpUser, provider.SmtpPwd);
                smtpClient.EnableSsl = Convert.ToBoolean(provider.SmtpSSL);
                smtpClient.Send(mailMessage);
            }
        }
开发者ID:felixthehat,项目名称:Limo,代码行数:28,代码来源:EmailHelper.cs

示例2: SendMail

        public StdResult<NoType> SendMail(string mailTo, string mailSubject, string mailContent, Attachment attachedFile, string ccs)
        {
            try
            {
                MailHelper mh = new MailHelper(MailType.BasicText);
                mh.MailSubject = mailSubject;
                mh.MailType = MailType.BasicText;
                string emailConf = mailTo;

                mh.Recipients = emailConf.Split(',').ToList().ConvertAll(emailAddress => new MailAddress(emailAddress));
                mh.Sender = new MailAddress("[email protected]");
                mh.ReplyTo = new MailAddress("[email protected]");
                mh.Content = mailContent;
                if(!string.IsNullOrWhiteSpace(ccs))
                    mh.CCs = ccs.Split(',').ToList().ConvertAll(emailAddress => new MailAddress(emailAddress));
                if (attachedFile != null)
                {
                    mh.Attachments = new List<Attachment> { attachedFile };
                }
                LogDelegate(string.Format("Mailer is gonna send a mail to {0}", mailTo));
                //mh.SetContentDirect(text);

                mh.Send();
                return StdResult<NoType>.OkResult;
            }
            catch (Exception e)
            {
                LogDelegate(string.Format("Exception while sending mail to {0}. E = {1} [{2}]", mailTo, e.Message, e.StackTrace));
                return StdResult<NoType>.BadResult(e.Message);
            }
        }
开发者ID:BlueInt32,项目名称:bundle-report,代码行数:31,代码来源:Mailer.cs

示例3: Button1_Click

 protected void Button1_Click(object sender, EventArgs e)
 {            
     DataView DV1 = (DataView)AccessDataSource1.Select(DataSourceSelectArguments.Empty);
     foreach (DataRowView DRV1 in DV1)
     {
         string ToAddress = DRV1["Email_Address"].ToString();
         MailMessage message = new MailMessage("[email protected]", ToAddress);                
         message.Body = TextBox2.Text;
         message.Subject = TextBox1.Text;
         message.BodyEncoding = System.Text.Encoding.UTF8;
         string Path = HttpContext.Current.Server.MapPath("~/images/EnewsLetters/Temp/");
         FileUpload1.SaveAs(Path + FileUpload1.FileName);
         Attachment attach1 = new Attachment(Path + FileUpload1.FileName);
         message.Attachments.Add(attach1);
         SmtpClient mailserver = new SmtpClient("amcsmail02.amcs.com", 25);
         try
         {
             mailserver.Send(message);
         }
         catch
         {
         }
         attach1.Dispose();
     }
     System.IO.File.Delete(HttpContext.Current.Server.MapPath("~/images/EnewsLetters/Temp/") + FileUpload1.FileName);
     TextBox1.Text = "";
     TextBox2.Text = "";
 }
开发者ID:tstanley93,项目名称:ARC.ORG-trunk,代码行数:28,代码来源:eNewsLetter_Email.aspx.cs

示例4: Index

        public ActionResult Index()
        {
            var outParam = new SqlParameter
            {
                ParameterName = "@result",
                Direction = ParameterDirection.Output,
                SqlDbType = SqlDbType.Int
            };

            List<Boolean> _BUEvent = db.Database.SqlQuery<Boolean>("sp_InsertIntoBuEventLog @result OUT", outParam).ToList();

            using (TransactionScope transaction = new TransactionScope())
            {

                bool result = _BUEvent.FirstOrDefault();
                if (result)
                {
                    var _vwSendEmail = (db.vwSendEmails.Where(a => a.CREATEDDATE == CurrentDate).Select(a => new { a.KDKC, a.email, a.NMKC,a.TAHUN,a.BULAN,a.MINGGU })).Distinct();
                    int count = 0;
                    foreach(var sending in _vwSendEmail)
                    {
                        MemoryStream memory = new MemoryStream();
                        PdfDocument document = new PdfDocument() { Url = string.Format("http://localhost:1815/AutoMail/PreviewPage?kdkc={0}", sending.KDKC) };
                        PdfOutput output = new PdfOutput() { OutputStream = memory };

                        PdfConvert.ConvertHtmlToPdf(document, output);
                        memory.Position = 0;
                        var SubjectName = string.Format("Reminder Masa Habis PKS Badan Usaha T{0} B{1} M{2}", sending.TAHUN, sending.BULAN, sending.MINGGU);
                        var attchName = string.Format("ReminderMasaHabisPKSBadanUsahaT{0}B{1}M{2}", sending.TAHUN, sending.BULAN, sending.MINGGU);
                        ContentType ct = new ContentType(MediaTypeNames.Application.Pdf);
                        Attachment data = new Attachment(memory, ct);
                        data.Name = attchName;
                        MailMessage message = new MailMessage();
                        message.To.Add(new MailAddress(sending.email));
                        message.From = new MailAddress("[email protected]", "Legal-InHealth Reminder ");
                        message.Subject = SubjectName;
                        message.Attachments.Add(data);
                        message.Body = sending.NMKC;
                        SmtpClient client = new SmtpClient();

                        try
                        {
                            client.Send(message);
                        }
                        catch (Exception ex)
                        {

                            ViewData["SendingException"] = string.Format("Exception caught in SendErrorLog: {0}",ex.ToString());
                            return View("ErrorSending", ViewData["SendingException"]);
                        }
                        data.Dispose();
                        // Close the log file.
                        memory.Close();
                        count += 1;
                    }
                }
                transaction.Complete();
            }
            return View();
        }
开发者ID:kacrut,项目名称:Legal,代码行数:60,代码来源:AutoMailController.cs

示例5: SendEmail

		public virtual void SendEmail(EmailServerSettings settings, string subject, string body, IEnumerable<MailAddress> toAddressList, MailAddress fromAddress, params EmailAttachmentData[] attachments)
		{
			using (var smtpClient = GetSmtpClient(settings))
			{
				var message = new MailMessage();
				message.From = fromAddress;
				message.Body = body;
				message.Subject = subject;
				message.IsBodyHtml = true;
				foreach (var toAddress in toAddressList)
				{
					message.To.Add(toAddress);
				}

				if (attachments != null)
				{
					foreach (var item in attachments)
					{
						var stream = StreamHelper.CreateMemoryStream(item.AttachmentData);
						stream.Position = 0;

						var attachment = new Attachment(stream, item.FileName);

						message.Attachments.Add(attachment);
					}
				}

				smtpClient.Send(message);
			}
		}
开发者ID:mmooney,项目名称:MMDB.RazorEmail,代码行数:30,代码来源:EmailSender.cs

示例6: Correo

        public Boolean Correo(String to, String sender, String from, String subject, String body, String pass, Attachment archivo)
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(from, sender);
            msg.To.Add(new MailAddress(to));
            msg.Subject = subject;
            msg.Body = body;
            msg.IsBodyHtml = true;

            if (archivo != null)
            {
                msg.Attachments.Add(archivo);
            }
            SmtpClient smtp = new SmtpClient();
            //smtp.Host = "smtp.mail.yahoo.com"; // yahoo
            //smtp.Host = "smtp.live.com"; // hotmail
            //smtp.Host = "localhost"; // servidor local
            smtp.Host = "smtp.gmail.com"; // gmail
            smtp.Port = 25;
            smtp.Credentials = new NetworkCredential(from, pass);
            smtp.EnableSsl = true;
            try
            {
                smtp.Send(msg);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
开发者ID:jeragones,项目名称:BolsaEmpleo,代码行数:31,代码来源:cCorreoComunicacion.cs

示例7: Send

        public static void Send(string server, string sender, string recipient, string subject,
    string body, bool isBodyHtml, Encoding encoding, bool isAuthentication, params string[] files)
        {
            SmtpClient smtpClient = new SmtpClient(server);
            MailMessage message = new MailMessage(sender, recipient);
            message.IsBodyHtml = isBodyHtml;

            message.SubjectEncoding = encoding;
            message.BodyEncoding = encoding;

            message.Subject = subject;
            message.Body = body;

            message.Attachments.Clear();
            if (files != null && files.Length != 0)
            {
                for (int i = 0; i < files.Length; ++i)
                {
                    Attachment attach = new Attachment(files[i]);
                    message.Attachments.Add(attach);
                }
            }

            if (isAuthentication == true)
            {
                smtpClient.Credentials = new NetworkCredential(SmtpConfig.Create().SmtpSetting.User,
                    SmtpConfig.Create().SmtpSetting.Password);
            }
            smtpClient.Send(message);
        }
开发者ID:x303597316,项目名称:ykcms,代码行数:30,代码来源:MailSender.cs

示例8: Attach

 public void Attach(string[] FileNames)
 {
     Array.ForEach(FileNames, (x) => {
         Attachment att = new Attachment(x);
         emailMess.Attachments.Add(att);
     });
 }
开发者ID:phamxuanlu,项目名称:MVC4-MobileStoreWeb,代码行数:7,代码来源:Message.cs

示例9: SendEmail

        public static void SendEmail(string from, string[] toAddresses, string[] ccAddresses, string subject, string body, System.IO.Stream stream, string filename)
        {
            MailMessage EmailMsg = new MailMessage();
            EmailMsg.From = new MailAddress(from);
            for (int i = 0; i < toAddresses.Count(); i++)
            {
                EmailMsg.To.Add(new MailAddress(toAddresses[i]));
            }
            for (int i = 0; i < ccAddresses.Count(); i++)
            {
                EmailMsg.CC.Add(new MailAddress(ccAddresses[i]));
            }
            EmailMsg.Subject = subject;
            EmailMsg.Body = body;
            EmailMsg.IsBodyHtml = true;
            EmailMsg.Priority = MailPriority.Normal;

            System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("Application/pdf");

            Attachment a = new Attachment(stream, ct);
            a.Name = filename;

            EmailMsg.Attachments.Add(a);

            SmtpClient MailClient = new SmtpClient();
            MailClient.Send(EmailMsg);
        }
开发者ID:nicholaswilliambrown,项目名称:ProfilesRNS_ORCID,代码行数:27,代码来源:Email.cs

示例10: SendMail

        public void SendMail(string smtpServer, string emailTo, string emailFrom, string password, string subject, string body, string fileLocation)
        {
            var fromAddress = new MailAddress(emailFrom, emailFrom);
            var toAddress = new MailAddress(emailTo, emailTo);
            var attachment = new Attachment(fileLocation);

            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(fromAddress.Address, password)
            };
            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body,
            })
            {
                message.Attachments.Add(attachment);
                smtp.Send(message);
            }
        }
开发者ID:jonorri,项目名称:ActionFolders,代码行数:25,代码来源:HelperFunction.cs

示例11: bt_enviar_Click

        protected void bt_enviar_Click(object sender, EventArgs e)
        {
            
            string Body = System.IO.File.ReadAllText(Server.MapPath("Mails/mail.htm"));
            adjunto = new Attachment("C:adjunto.txt"); //lo adjuntamos
            msg.Attachments.Add(adjunto);

            msg.Body = Body;
            msg.IsBodyHtml = true;
           
            msg.From = new MailAddress("[email protected]");
            msg.To.Add("[email protected]");
            msg.Subject = "Centro Salud-Información";
            client.Credentials = new NetworkCredential("[email protected]", "sistemamaipu");
            client.Host = "smtp.gmail.com";
            client.Port = 25;
            client.EnableSsl = true;
            client.Send(msg);
            //falta mostrar mensaje de mail enviado!!!!!!!!!!!!!!
            //Darle mejor formato al mail
            //Configurar donde se van guardar los adjuntos..
            //habría que ver donde se generan los reportes!

            

        }
开发者ID:NatiGiova,项目名称:habilitacion-profesional-alelopez,代码行数:26,代码来源:ProbarAlertas.aspx.cs

示例12: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                mail = new MailMessage();
                SmtpServer = new SmtpClient("smtp.yourdomain.com");
                mail.From = new MailAddress("[email protected]");
                mail.To.Add(combo.Items[combo.SelectedIndex].ToString());
                mail.Subject = subjbox.Text.ToString();
                mail.Body = msgbox.Text.ToString();
                if (strFileName != string.Empty)
                {
                    System.Net.Mail.Attachment attachment;
                    attachment = new System.Net.Mail.Attachment(strFileName);
                    mail.Attachments.Add(attachment);

                    SmtpServer.Send(mail);
                    MessageBox.Show("Sent Message With Attachment", "MMS by Paul");
                }

                else {
                    SmtpServer.Send(mail);
                    MessageBox.Show("Sent Message", "MMS by Paul");
                     }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
开发者ID:jorik041,项目名称:ArcGIS-DesktopExplorer-MMS-Plugin,代码行数:32,代码来源:Form1.cs

示例13: Build_MessageHasAttachments_AddsAttachmentParts

 public void Build_MessageHasAttachments_AddsAttachmentParts()
 {
     var attachment = new Attachment(new MemoryStream(), "Test Attachment");
     var message = BuildMessage(x => x.Attachments.Add(attachment));
     var result = FormPartsBuilder.Build(message);
     result.AssertContains(attachment);
 }
开发者ID:typesafe,项目名称:mnailgun,代码行数:7,代码来源:FormPartsBuilderTests.cs

示例14: SendMail

        /// <summary>
        /// Отправка почтовое сообщение
        /// </summary>
        /// <param name="mailFrom">адрес от</param>
        /// <param name="mailTo">адрес кому</param>
        /// <param name="mailSubject">предмет сообщения (заголовок)</param>
        /// <param name="mailBody">текст сообщения</param>
        /// <param name="mailSmtpServer">почтовый сервер</param>
        /// <param name="FileName">наименование файла</param>
        /// <returns>успех/неудача</returns>
        public static bool SendMail(string mailFrom, string mailTo, string mailSubject, string mailBody, IEnumerable<HttpPostedFileBase> files, bool isHtml = true) {
            bool _mailSended;
            try {
                MailMessage message = new MailMessage(mailFrom, mailTo, mailSubject, mailBody);
                if (files != null) {
                    foreach (HttpPostedFileBase file in files) {
                        Attachment data = new Attachment(file.InputStream, file.ContentType);
                        ContentDisposition disposition = data.ContentDisposition;
                        disposition.CreationDate = System.IO.File.GetCreationTime(file.FileName);
                        disposition.ModificationDate = System.IO.File.GetLastWriteTime(file.FileName);
                        disposition.ReadDate = System.IO.File.GetLastAccessTime(file.FileName);
                        message.Attachments.Add(data);
                    }
                }
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.SubjectEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml = isHtml;

                SmtpClient client = new SmtpClient("localhost");
                client.Credentials = CredentialCache.DefaultNetworkCredentials;
                client.Send(message);
                _mailSended = true;
            }
            catch (Exception ex) {
                _mailSended = false;
                string inner = ex.InnerException != null ? inner = ex.InnerException.Message : "нет";
            }
            return _mailSended;
        }
开发者ID:hidepii,项目名称:client-valid-disabler,代码行数:39,代码来源:MvcHelper.cs

示例15: SendMail

        public void SendMail(string MailTo, string MailFrom, string attachFiles, string Subject, String Content)
        {
            try
            {
                string from = MailFrom;
                MailAddress mailFrom = new MailAddress(from);
                string to = MailTo;
                MailAddress mailTo = new MailAddress(to);

                using (MailMessage message = new MailMessage(mailFrom, mailTo))
                {
                    message.Priority = MailPriority.Normal;
                    message.Subject = Subject;
                    message.Body = Content;
                    message.Priority = MailPriority.Normal;
                    if (!string.IsNullOrWhiteSpace(attachFiles))
                    {
                        Attachment fileToAttch = new Attachment(attachFiles);
                        message.Attachments.Add(fileToAttch);
                    }

                    SmtpClient client = new SmtpClient();

                    client.Send(message);
                }
            }
            catch (Exception ex)
            {
                //Log Exceptions
            }
        }
开发者ID:pankajdey198320,项目名称:MYRND,代码行数:31,代码来源:ForgotPassword.aspx.cs


注:本文中的System.Net.Mail.Attachment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。