110,535
社区成员
发帖
与我相关
我的任务
分享
string fjrtxt = "aaa0323@163.com"; //发件者邮箱地址
string mmtxt = "qq123"; //发件者邮箱密码
string sjrtxt = "35435345@qq.com";//收件人收箱地址
string zttxt = "这是厕所";//主题
string nrtxt = "这是测试";//内容
string[] fasong = fjrtxt.Split('@');
string[] fs = fasong[1].Split('.');
//发送
SmtpClient client = new SmtpClient("smtp." + fs[0].ToString().Trim() + ".com"); //设置邮件协议
client.UseDefaultCredentials = false;//这一句得写前面
client.DeliveryMethod = SmtpDeliveryMethod.Network; //通过网络发送到Smtp服务器
client.Credentials = new NetworkCredential(fasong[0].ToString(), mmtxt); //通过用户名和密码 认证
MailMessage mmsg = new MailMessage(new MailAddress(fjrtxt), new MailAddress(sjrtxt)); //发件人和收件人的邮箱地址
mmsg.Subject = zttxt; //邮件主题
mmsg.SubjectEncoding = Encoding.UTF8; //主题编码
mmsg.Body = nrtxt; //邮件正文
mmsg.BodyEncoding = Encoding.UTF8; //正文编码
mmsg.IsBodyHtml = true; //设置为HTML格式
mmsg.Priority = MailPriority.High; //优先级
try
{
client.Send(mmsg);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "图像文件 (*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG"; //上傳格式
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fullpath = openFileDialog1.FileName;//文件路径
System.Net.WebClient myWebClient = new System.Net.WebClient();
myWebClient.UploadFile("http://localhost/up/Uploader.ashx", "POST", fullpath);
}
<%@ WebHandler Language="C#" Class="Uploader" %>
using System;
using System.Web;
using System.IO;
public class Uploader : IHttpHandler {
public void ProcessRequest(HttpContext hc)
{
foreach (string fileKey in hc.Request.Files)
{
HttpPostedFile file = hc.Request.Files[fileKey];
file.SaveAs(Path.Combine(hc.Server.MapPath("."), file.FileName));
}
}
public bool IsReusable
{
get { return true; }
}
}