发送Email并添加附件
1. 添加命名空间
using System.Net.Mail;
using System.Net;
2. The HTML MarpUp
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="From:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFrom" runat="server" Height="17px" Width="231px"></asp:TextBox>
</td>
</tr> <tr>
<td>
<asp:Label ID="Label3" runat="server" Text="To:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtTo" runat="server" Height="19px" Width="226px"></asp:TextBox>
</td>
</tr> <tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Subject:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtSubject" runat="server" Height="19px" Width="240px"></asp:TextBox>
</td>
</tr> <tr>
<td>
<asp:Label ID="Label4" runat="server" Text="Body:"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine" Height="102px" Width="234px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="Accachment:"></asp:Label>
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<tr>
<td colspan="" style="text-align:center">
<asp:Button ID="Button1" runat="server" Text="Send" OnClick="Button1_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
3. 封装了一个发送Email的方法,根据此方法添加相应的参数,即可进行发功邮件
protected void SendMail(string FromAddress, string ToAddress, string Subject, string Body, string UserName, string Password)
{
// smtp settings
SmtpClient smtp = new SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = ;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(UserName, Password);
smtp.Timeout = ;
} //mail settings
MailMessage mail = null;
if (FileUpload1.HasFile)
{
mail = new MailMessage(FromAddress, ToAddress, Subject, Body);
//add attachment file
String FileName = FileUpload1.PostedFile.FileName;
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(FileName);
mail.Attachments.Add(attachment);
}
smtp.Send(mail);
}
More relevant information:
http://www.aspdotnet-suresh.com/2010/12/how-to-send-mail-using-gmail.html
http://forums.asp.net/t/1691720.aspx?TIME+OUT+ERROR+
http://www.codeproject.com/Answers/321575/sending-email-to-gmail-from-asp-net#answer3
http://www.codeproject.com/Questions/582062/Gettingplusanpluserrorplus-OperationplusTimedpluso
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.timeout(v=vs.110).aspx
发送Email并添加附件的更多相关文章
- VC++ 利用MAPI实现在程序中调用默认的电子邮件程序发送EMAIL(可以添加附件)。
1.利用ShellExecute 可以条用默认邮件客户端,但不能发送带附件的邮件 mailto:用户账号@邮件服务器地址?subject=邮件主题&body=邮件正文 如:ShellExe ...
- python 发送email邮件带附件
EMAIL功能实现: 1.发送EMAIL带附件,并且带压缩文件夹做为附件 #_*_coding:utf-8_*_ import smtplib from email.mime.text import ...
- 使用spring 并加载模板发送Email 发邮件 java 模板
以下例子是使用spring发送email,然后加载到固定的模板,挺好的,大家可以试试 需要使用到spring-context 包 和 com.springsource.org.apache.veloc ...
- 【ABAP系列】SAP ABAP实现发送外部邮件(添加附件)功能
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP ABAP实现发送外部邮件(添 ...
- Jmail组件-----发送email
jmail是一个第三方邮件操作组件,通常位于web服务器端,和站点程序紧密配合来接收及提交邮件到邮件服务器的控件,让网站拥有发送邮件既接收邮件的功能. 之所以想尝试它的理由呢 是因为----jmail ...
- 使用PHP发送email进行账号激活或者密码修改操作
使用PHPMailer编写发送邮件 PHPMailer需PHP的socket扩展支持,而PHPMailer链接qq域名邮箱时需要ssl加密方式(qq邮箱最近做了限制,新开域名邮箱不再允许通过smtp协 ...
- 【WinForm】C# 发送Email
发送Email 的条件 1.SmtpClient SMTP 协议 即 Host 处理事务的主机或IP地址 //smtp.163.com UseDefaultCredentia ...
- IOS发送Email的两种方法-备
1.openURL 使用openURL调用系统邮箱客户端是我们在IOS3.0以下实现发邮件功能的主要手段.我们可以通过设置url里的相关参数来指定邮件的内容,不过其缺点很明显,这样的过程会导致程序暂时 ...
- 使用VS2003 发送Email
使用VS2003发送Email与之后VS2005版本及以上VS版本不一样,记录一下, 需要引用using System.Web.Mail; public void SendEmail() { try ...
随机推荐
- eclipse run on server 浏览器启动设置
- codevs 1455 路径 计算m^n%p
题目链接 题目描述 Description 小明从A1到An+1,他知道从A1到A2,从A2到A3,......,从An到An+1都有m条路,且从A1到An+1都只有这些路.小明想知道,从A1地到An ...
- python 关于dict的一些总结
总结了一些关于字典的小技巧或者注意的地方. 使用zip创建字典 创建字典有以下三种方法 dict(a=1, b=2, c=2) dict([(a,1), (b,2), (c,3)]) dict({a: ...
- spring util命名空间
在spring的配置文件中util命名空间类似于java.util包类对应,util命名空间提供了集合相关的配置,在使用命名空间前要导入util命名空间,如下: util命名空间引入 <bean ...
- Linux 查看文件
1: cat file_full_name 这种方法适合查看小文件 cat /etc/services cat -n file_full_name -n 可以加行号! 2: tac file_ful ...
- 《转》使用JAVA如何对图片进行格式检查以及安全检查处理
本文出自冯立彬的博客,原地址:http://www.fenglibin.com/use_java_to_check_images_type_and_security.html 一.通常情况下,验证一个 ...
- System timers granularity
http://code.google.com/p/javasimon/wiki/SystemTimersGranularity
- Eclipse启动后一直Initializing Java Tooling (1%)
问题症状: 工作中eclipse崩溃,再次启动后cpu占用99%,状态栏一直显示Initializing Java Tooling: (1%). 解决方案: 删除\workspace\.metadat ...
- Shell 脚本小试牛刀(番外) -- 捷报
捷报 捷报 捷报 捷报 捷报 捷报来袭,本系列的脚本已在Github 上开了版块, 我命名为" easy shell "(点此进入). 眼下已加入前面几期中的脚本,日后还会有很多其 ...
- xcode 工具栏中放大镜的替换的说明
1.如果是在打开的文档范围内: 查找: Command+ F 替换: Option+Command+F Replace All 是全部替 ...