本文整理汇总了C#中System.Net.Mail.Attachment类的典型用法代码示例。如果您正苦于以下问题:C# Attachment类的具体用法?C# Attachment怎么用?C# Attachment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Attachment类属于System.Net.Mail命名空间,在下文中一共展示了Attachment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: enviarCorreo
public void enviarCorreo(string emisor, string password, string mensaje, string asunto, string destinatario, string ruta)
{
try
{
correos.To.Clear();
correos.Body = "";
correos.Subject = "";
correos.Body = mensaje;
correos.Subject = asunto;
correos.IsBodyHtml = true;
correos.To.Add(destinatario.Trim());
if (ruta.Equals("") == false)
{
System.Net.Mail.Attachment archivo = new System.Net.Mail.Attachment(ruta);
correos.Attachments.Add(archivo);
}
correos.From = new MailAddress(emisor);
envios.Credentials = new NetworkCredential(emisor, password);
//Datos importantes no modificables para tener acceso a las cuentas
envios.Host = "smtp.gmail.com";
envios.Port = 587;
envios.EnableSsl = true;
envios.Send(correos);
MessageBox.Show("El mensaje fue enviado correctamente");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "No se envio el correo correctamente", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
开发者ID:Jrevmen,项目名称:ClinicaFinal,代码行数:35,代码来源:clasCorreo.cs
示例17: SendMail
public static bool SendMail(string fromEmail, List<string> emailTo, List<string> emailCC, string subjectLine,
string bodyText, bool isHTML, List<string> attachments)
{
HttpContext context = HttpContext.Current;
EMailSettings mailSettings = EMailSettings.GetEMailSettings();
if (String.IsNullOrEmpty(fromEmail)) {
fromEmail = mailSettings.ReturnAddress;
}
if (emailTo != null && emailTo.Any()) {
MailMessage message = new MailMessage {
From = new MailAddress(fromEmail),
Subject = subjectLine,
Body = bodyText,
IsBodyHtml = isHTML
};
message.Headers.Add("X-Computer", Environment.MachineName);
message.Headers.Add("X-Originating-IP", context.Request.ServerVariables["REMOTE_ADDR"].ToString());
message.Headers.Add("X-Application", "Carrotware Web " + CurrentDLLVersion);
message.Headers.Add("User-Agent", "Carrotware Web " + CurrentDLLVersion);
message.Headers.Add("Message-ID", "<" + Guid.NewGuid().ToString().ToLowerInvariant() + "@" + mailSettings.MailDomainName + ">");
foreach (var t in emailTo) {
message.To.Add(new MailAddress(t));
}
if (emailCC != null) {
foreach (var t in emailCC) {
message.CC.Add(new MailAddress(t));
}
}
if (attachments != null) {
foreach (var f in attachments) {
Attachment a = new Attachment(f, MediaTypeNames.Application.Octet);
ContentDisposition disp = a.ContentDisposition;
disp.CreationDate = System.IO.File.GetCreationTime(f);
disp.ModificationDate = System.IO.File.GetLastWriteTime(f);
disp.ReadDate = System.IO.File.GetLastAccessTime(f);
message.Attachments.Add(a);
}
}
SmtpClient client = new SmtpClient();
if (mailSettings.DeliveryMethod == SmtpDeliveryMethod.Network
&& !String.IsNullOrEmpty(mailSettings.MailUserName)
&& !String.IsNullOrEmpty(mailSettings.MailPassword)) {
client.Host = mailSettings.MailDomainName;
client.Credentials = new NetworkCredential(mailSettings.MailUserName, mailSettings.MailPassword);
} else {
client.Credentials = new NetworkCredential();
}
client.Send(message);
}
return true;
}
开发者ID:ninianne98,项目名称:CarrotCakeCMS,代码行数:60,代码来源:EmailHelper.cs
示例18: AddAttachments
///<summary>
/// 添加附件
///</summary>
///<param name="attachPaths">附件的路径集合,以分号分隔</param>
public bool AddAttachments(string attachPaths)
{
bool isSuccess = true;
try
{
string[] paths = attachPaths.Split(';'); //以什么符号分隔可以自定义
Attachment attachment;
ContentDisposition disposition;
foreach (string path in paths)
{
if (!File.Exists(path))
continue;
attachment = new Attachment(path, MediaTypeNames.Application.Octet);
attachment.Name = System.IO.Path.GetFileName(path);
attachment.NameEncoding = System.Text.Encoding.GetEncoding("gb2312");
attachment.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
disposition = attachment.ContentDisposition;
disposition.Inline = true;
disposition.DispositionType = System.Net.Mime.DispositionTypeNames.Inline;
disposition.CreationDate = File.GetCreationTime(path);
disposition.ModificationDate = File.GetLastWriteTime(path);
disposition.ReadDate = File.GetLastAccessTime(path);
this.m_mail.Attachments.Add(attachment);
}
}
catch (Exception)
{
isSuccess = false;
}
return isSuccess;
}
开发者ID:chengliangkaka,项目名称:Prepaid,代码行数:36,代码来源:EmailHelper.cs
示例19: SendEmail
public static void SendEmail(EmailSenderData emailData)
{
MailMessage mail = new MailMessage();
SmtpClient smtpServer = new SmtpClient(emailData.SmtpClient);
smtpServer.Port = 25;
mail.From = new MailAddress(emailData.FromEmail);
foreach (string currentEmail in emailData.Emails)
{
mail.To.Add(currentEmail);
}
mail.Subject = emailData.Subject;
mail.IsBodyHtml = true;
mail.Body = emailData.EmailBody;
if (emailData.AttachmentPath != null)
{
foreach (string currentPath in emailData.AttachmentPath)
{
Attachment attachment = new Attachment(currentPath);
mail.Attachments.Add(attachment);
}
smtpServer.Send(mail);
DisposeAllAttachments(mail);
}
else
{
smtpServer.Send(mail);
}
mail.Dispose();
smtpServer.Dispose();
}
开发者ID:kennedykinyanjui,项目名称:Projects,代码行数:33,代码来源:EmailSender.cs
示例20: CSmtpClient
/// <summary>
/// Constructor for Custom Smtp Client.
/// </summary>
/// <param name="usr">Username</param>
/// <param name="pass">Password</param>
/// <param name="mailTo">Email address of the recipient</param>
/// <param name="mailFrom">Who the mail is coming from</param>
/// <param name="subject">The Subject of the email</param>
/// <param name="attachments">Attachemts added to email</param>
public CSmtpClient(string usr, string pass, string mailTo, string mailFrom, string subject, string message, Attachment[] attachments)
: this(usr, pass, mailTo, mailFrom, subject, message)
{
foreach (Attachment att in attachments)
objMail.Attachments.Add(att);
this.usr = usr;
}
开发者ID:pavlin-policar,项目名称:SimpleMailClient,代码行数:16,代码来源:CSmtpClient.cs
注:本文中的System.Net.Mail.Attachment类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论