如何使用C#在Web应用程序中发送带附件的电子邮件 [英] How to send email with attachment in web application in C#
本文介绍了如何使用C#在Web应用程序中发送带附件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Plz告诉我如何在C#中发送带有附件的电子邮件#div class =h2_lin>解决方案
任何努力?这已经完成了很多次,互联网上充满了例子。
无论如何,请看这个通用示例发送电子邮件:
使用C#发送电子邮件有或没有附件:通用例程。 [ ^ ]
请注意,客户端当然没有C#,所以基本上问题是要么发送使用Javascirpt发送邮件或使用C#在服务器端发送邮件。
这是C#的示例,如下所示:MailMessage mail = new MailMessage( recipient@hisDomain.com, you@yourdomain.com);
SmtpClient client = new SmtpClient();
client.Port = 25 ;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false ;
client.Host = smtp.google.com;
mail.Subject = 主题。;
mail.Body = 正文文本;
client.Credentials = new NetworkCredential( account@gmail.com, password);
client.Send(mail);
干杯,
Edo
尝试类似的事情。
尝试
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient( smtp .gmail.com跨度>);
mail.From = new MailAddress( your_email_address@gmail.com跨度>);
mail.To.Add( to_address);
mail.Subject = Test Mail - 1;
mail.Body = 带附件的邮件;
System.Net.Mail.Attachment附件;
attachment = new System.Net.Mail.Attachment( 您的附件);
mail.Attachments.Add(附件);
SmtpServer.Port = 587 ;
SmtpServer.Credentials = new System.Net.NetworkCredential( username, password);
SmtpServer.EnableSsl = true ;
SmtpServer.Send(mail);
MessageBox.Show( mail send);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
或者,查看..
用于在C#中发送带附件的电子邮件的类。 [ ^ ]
如何发送邮件 - -attachment-in.html [ ^ ]
Plz tell me How to send email with attachment in web application in C#
解决方案
Any effort? This has been done so many times and internet is full of examples.
Anyway, look at this generic example to send emails:
Sending an Email in C# with or without attachments: generic routine.[^]
Please note that there is no C# on the client side of course, so basically the question is either send mail using Javascirpt OR send mail on the server side using C#.
This is an example for C#, as requested:MailMessage mail = new MailMessage("recipient@hisDomain.com", "you@yourdomain.com"); SmtpClient client = new SmtpClient(); client.Port = 25; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Host = "smtp.google.com"; mail.Subject = "The subject."; mail.Body = "Body text here"; client.Credentials = new NetworkCredential("account@gmail.com", "password"); client.Send(mail);
Cheers,
Edo
Try something like..
try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("your_email_address@gmail.com"); mail.To.Add("to_address"); mail.Subject = "Test Mail - 1"; mail.Body = "mail with attachment"; System.Net.Mail.Attachment attachment; attachment = new System.Net.Mail.Attachment("your attachment file"); mail.Attachments.Add(attachment); SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); MessageBox.Show("mail Send"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); }
Or, view..
A class for sending emails with attachments in C#.[^]
How-to-send-mail-with-attachment-in.html[^]
这篇关于如何使用C#在Web应用程序中发送带附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文