发送带附件的邮件 [英] Send mail with attach file
本文介绍了发送带附件的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友
请帮我如何发送带附件的邮件。我已成功发送没有附件的邮件,但我不知道如何创建发送附件的代码,所以请帮助我
== >以下是我为没有附加邮件代码而编写的代码
Hi Friends
Please help me how to send mail with attach file. i have successfully send mail without attach file but i dont know how to create code which send attach file so please help me
==>Following is the code i written for without attach mail code
protected void OboutButton1_Click(object sender, EventArgs e)
{
MailMessage loginInfo = new MailMessage();
loginInfo.To.Add(txt_email.Text.ToString());
loginInfo.From = new MailAddress("my email id");
loginInfo.Subject = "Contact Detail";
loginInfo.Body = "Message: " + txt_message.Text;
loginInfo.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("my email id", "my password");
smtp.Send(loginInfo);
}
推荐答案
使用SMTP服务器在ASP.NET中发送带附件的电子邮件 [ ^ ]
在Asp.Net中发送带附件的电子邮件 [ ^ ]
如何在asp.net中使用附件发送邮件 [ ^ ]
如何在asp.net中发送带有多个附件的邮件 [ ^ ]
Sending Email with attachment in ASP.NET using SMTP Server[^]
Send Email With Attachment In Asp.Net [^]
how to send mail with attachement in asp.net [^]
How to send mail with multiple attachments in asp.net [^]
public static void CreateMessageWithAttachment(string server)
{
// Specify the file to be attached and sent.
// This example assumes that a file named Data.xls exists in the
// current working directory.
string file = "data.xls";
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
"jane@contoso.com",
"ben@contoso.com",
"Quarterly data report.",
"See the attached spreadsheet.");
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
//Send the message.
SmtpClient client = new SmtpClient(server);
// Add credentials if the SMTP server requires them.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
try {
client.Send(message);
}
catch (Exception ex) {
Console.WriteLine("Exception caught in CreateMessageWithAttachment(): {0}",
ex.ToString() );
}
// Display the values in the ContentDisposition for the attachment.
ContentDisposition cd = data.ContentDisposition;
Console.WriteLine("Content disposition");
Console.WriteLine(cd.ToString());
Console.WriteLine("File {0}", cd.FileName);
Console.WriteLine("Size {0}", cd.Size);
Console.WriteLine("Creation {0}", cd.CreationDate);
Console.WriteLine("Modification {0}", cd.ModificationDate);
Console.WriteLine("Read {0}", cd.ReadDate);
Console.WriteLine("Inline {0}", cd.Inline);
Console.WriteLine("Parameters: {0}", cd.Parameters.Count);
foreach (DictionaryEntry d in cd.Parameters)
{
Console.WriteLine("{0} = {1}", d.Key, d.Value);
}
data.Dispose();
}
这篇关于发送带附件的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文