使用C#中的多个电子邮件附件文件 [英] Multiple attachment file in email using C#

查看:319
本文介绍了使用C#中的多个电子邮件附件文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#中的多个文件附加在电子邮件

 邮件MAILMESSAGE新= MAILMESSAGE(); 
SmtpClient SMTPSERVER =新SmtpClient(smtp.gmail.com);

//获取用户ID,通
用户ID = register.userName;
密码= register.pass;


串AA = txtTo.Text;
mail.From =新的MailAddress(用户ID);
mail.To.Add(AA);
mail.Subject = txtsubject.Text;
mail.Body = txtComments.Text;

//附加文件
mail.Attachments.Add(新附件(txtAttachments.Text.ToString()));
SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = FALSE;
SmtpServer.Credentials =新System.Net.NetworkCredential(用户ID,密码);
SmtpServer.EnableSsl = TRUE;
SmtpServer.Send(邮件);
MessageBox.Show(邮件发送成功);
this.Cursor = Cursors.Default;

//关闭页面
电子邮件电子邮件=新的电子邮件();
email.Close();

此代码用于连接只有一个文件。我怎么能把在C#2008多个文件。???
PLZ给我的解决方案。


解决方案

  ... 
mail.Body = txtComments.Text;
//附加文件
mail.Attachments.Add(新附件(txtAttachments.Text.ToString()));
mail.Attachments.Add(新附件(txtAttachments2.Text.ToString()));
mail.Attachments.Add(新附件(txtAttachments3.Text.ToString()));
mail.Attachments.Add(新附件(txtAttachments4.Text.ToString()));
SmtpServer.Port = 587;
...


How to attach the multiple files in an email using c#.

        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

        //get the userID, Pass
        userID= register.userName;
        password = register.pass;


        string aa=txtTo.Text;
        mail.From = new MailAddress(userID);
        mail.To.Add(aa);
        mail.Subject = txtsubject.Text;
        mail.Body = txtComments.Text;

        //Attach file
        mail.Attachments.Add(new Attachment(txtAttachments.Text.ToString()));       
        SmtpServer.Port = 587;
        SmtpServer.UseDefaultCredentials = false;
        SmtpServer.Credentials = new System.Net.NetworkCredential(userID, password);
        SmtpServer.EnableSsl = true;
        SmtpServer.Send(mail);
        MessageBox.Show("Email sent successfully");
        this.Cursor = Cursors.Default;

        //close the page
        Email email = new Email();
        email.Close();

this code is used for attach one file only. How can i attach multiple files in c# 2008.??? Plz give me the solution.

解决方案

...
mail.Body = txtComments.Text;
//Attach file
mail.Attachments.Add(new Attachment(txtAttachments.Text.ToString()));
mail.Attachments.Add(new Attachment(txtAttachments2.Text.ToString()));
mail.Attachments.Add(new Attachment(txtAttachments3.Text.ToString()));
mail.Attachments.Add(new Attachment(txtAttachments4.Text.ToString()));
SmtpServer.Port = 587;
...

这篇关于使用C#中的多个电子邮件附件文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆