发送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 ...
随机推荐
- Ubuntu14下LAMP环境的安装以及yaf扩展的安装
前段时间在ubuntu下安装了lamp环境,记录一下安装过程方便以后查阅. 安装lamp环境 ① 安装apache sudo apt-get install apache2 系统会弹出如图所示的提示, ...
- 【LeetCode题意分析&解答】35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- MySQL mysqlimport 从txt文件中导入数据到mysql数据库
mysqlimport: 我说这个我们还是先从世界观方法论的高度来理解一下便有更加准确的把握.数据导入不外呼有两个部分 第一部分:目标对象--我们要把数据导给谁(mysqlimport 的目标对象自然 ...
- JAVA并发,锁与方法
引自:<thinking in java> synchronized void f(){/* ... */}; synchronized void g(){/* ... */}; 所有对象 ...
- Qt项目管理(33个规则)
2016-06-20 花莫弦 小小杂货铺LY 一.qmake的介绍 qmake是Trolltech公司创建的用来为不同的平台和编译器书写Makefile的工具. 手写Makefile是比较困难并且容易 ...
- c++ 静态多态与动态多态
多态polymorphism是指具有多种形态的情况,它能根据单一的标记关联不同的行为.多态是面向对象程序设计的基础.在面向对象程序设计中的多态是一种运行时的多态.C++中有两种多态,称为动多态(运行时 ...
- 对开发中常见的内存泄露,GDI泄露进行检测
对开发中常见的内存泄露,GDI泄露进行检测 一.GDI泄露检测方法: 在软件测试阶段,可以通过procexp.exe 工具,或是通过任务管理器中选择GDI对象来查看软件GDI的对象是使用情况. 注意点 ...
- Struts 和Spring的核心控制器
Struts 核心控制器是FilterDispatch Spring核心控制器是DispatchServlet
- linux系统的安装
安装linux系统须要选择一个linux操作系统,有redhat,ubuntu,centos,这里选择centos进行linux系统的安装 首先在centos的官方站点下载镜像文件CentOS-6.5 ...
- c#学习心得,慢慢添加,如果有错误希望大家留言,我刚开始学
1.class类:相当于整个项目的一个功能性程序,为了阐述系统中某个对象的功能. 方法:相当于程序的一个功能部件.可以被其他方法或类调用?感觉这个问题有点复杂 c#框架结构:我目前接触到的 using ...