Stmp发送邮件-创新互联
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
namespace Email
{
public partial class SMTP : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
string file = Server.MapPath("testXML.xml");
MailMessage myMail = new System.Net.Mail.MailMessage();
string senderText = txtSender.Text.Trim();//获取或设置此电子邮件的发件人地址
string receiverText = txtReceiver.Text.Trim();//获取或设置此电子邮件的收件人地址
string subjectText = txtSubject.Text.Trim();//获取或设置次电子邮件的主题
string bodyText = txtSender.Text.Trim();//获取或设置邮件正文
myMail = new System.Net.Mail.MailMessage(senderText, receiverText, subjectText, bodyText);
//附件
if (ddlAccessories.Items.Count > 0)
{
for (int i = 0; i < ddlAccessories.Items.Count; i++)
{
System.Net.Mail.Attachment myAttachment = new System.Net.Mail.Attachment(Server.MapPath(ddlAccessories.Items[i].Value), System.Net.Mime.MediaTypeNames.Application.Octet);
System.Net.Mime.ContentDisposition disposition = myAttachment.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
myMail.Attachments.Add(myAttachment);
}
}
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("175.191.40.253", 25);
client.Credentials = new System.Net.NetworkCredential("www.459643912380@qq.com", "w123z123q121q31we21233729281812301");
client.Send(myMail);
}
protected void btnTake_Click(object sender, EventArgs e)
{
if (upFile.PostedFile.ContentLength != 0)
{
string clientFileName = upFile.PostedFile.FileName;
string[] strTemp = clientFileName.Split('.');
string upFileExp = strTemp[strTemp.Length - 1].ToString();
string ServerFileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp;
upFile.PostedFile.SaveAs(Server.MapPath(ServerFileName));
ddlAccessories.Items.Add(new ListItem(clientFileName, ServerFileName));
if (ddlAccessories.Items.Count > 0)
{
btnDelete.Enabled = true;
}
else
{
btnDelete.Enabled = false;
}
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SMTP.aspx.cs" Inherits="Email.SMTP" %>
文章名称:Stmp发送邮件-创新互联
本文URL:http://pwwzsj.com/article/ihphi.html