http://www.cnblogs.com/jessezhao/archive/2007/01/16/621946.html
解决方案 »
- 高分求援
- 水晶报表如何更改宽度?
- 请问这个功能是怎么实现的??
- c#中求两个日期之差用什么函数
- web用户控件的问题,各位帮忙看看,多谢
- 如何檢查dropDownList中有沒有value為"RMB"
- 两个服务器,只有一个装了vs.net,如何在另一个服务器上添加.Net框架组件的问题??请高手来看看,谢谢!
- 一个页面怎么操作在它上面的用户自定义控件?
- ~~~~~~~~~~~~控件位置的问题~~~~~~~~~~~~~~~~
- 急!c#中调用存储过程,有何数据类型对应sqlserver2000中的numeric?可以传值?
- 【求助】在本机使用WebService时出现错误,请路过好人帮忙看看。
- 请问如何从后台获取当前活动控件的id?比如在点击textbox时,后台能够得到它的ID
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;
namespace Examples.SmptExamples.Async
{
public class SimpleAsynchronousExample
{
static bool mailSent = false;
public static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
{
// Get the unique identifier for this asynchronous operation.
String token = (string) e.UserState;
if (e.Cancelled)
{
Console.WriteLine("[{0}] Send canceled.", token);
}
if (e.Error != null)
{
Console.WriteLine("[{0}] {1}", token, e.Error.ToString());
} else
{
Console.WriteLine("Message sent.");
}
mailSent = true;
}
public static void Main(string[] args)
{
// Command line argument must the the SMTP host.
SmtpClient client = new SmtpClient(args[0]);
// Specify the e-mail sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress("[email protected]",
"Jane " + (char)0xD8+ " Clayton",
System.Text.Encoding.UTF8);
// Set destinations for the e-mail message.
MailAddress to = new MailAddress("[email protected]");
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test e-mail message sent by an application. ";
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] {'\u2190', '\u2191', '\u2192', '\u2193'});
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1" + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// Set the method that is called back when the send operation ends.
client.SendCompleted += new
SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your callback
// method to identify this send operation.
// For this example, the userToken is a string constant.
string userState = "test message1";
client.SendAsync(message, userState);
Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
string answer = Console.ReadLine();
// If the user canceled the send, and mail hasn't been sent yet,
// then cancel the pending operation.
if (answer.StartsWith("c") && mailSent == false)
{
client.SendAsyncCancel();
}
// Clean up.
message.Dispose();
Console.WriteLine("Goodbye.");
}
}
}
myMail.From = EMAIL_ADDRESS;
myMail.To = strEmail;
myMail.Subject = "邮件确认";
myMail.BodyFormat = MailFormat.Text;
myMail.Body = "内容";
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", EMAIL_ADDRESS);myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", EMAIL_PASSWORD);
SmtpMail.SmtpServer = EMAIL_SERVER;
SmtpMail.Send(myMail);
/// 发送邮件
/// </summary>
/// <param name="sMailServer"></param>
/// <param name="sMailServerUserName"></param>
/// <param name="sMailServerUserPassword"></param>
/// <param name="sFrom"></param>
/// <param name="sTo"></param>
/// <param name="sCc"></param>
/// <param name="sSubject"></param>
/// <param name="sBody"></param>
/// <param name="isBodyHtml"></param>
/// <param name="mailPriority"></param>
/// <returns></returns>
public static ReturnValue SendEmail(string sMailServer,string sMailServerUserName,string sMailServerUserPassword,string sFrom, string sTo, string sCc, string sSubject, string sBody,bool isBodyHtml,System.Net.Mail.MailPriority mailPriority)
{
ReturnValue retValue = new ReturnValue(); if (sMailServer == "")
{
retValue.HasError = true;
retValue.Message = "系统没有配置发送邮件的服务器名称!";
return retValue;
}
if (sFrom == "")
{
retValue.HasError = true;
retValue.Message = "系统没有配置发送邮件的帐号!";
return retValue;
} string sBodyEncoding; sBodyEncoding = Encoding.Default.EncodingName;
MailMessage MyMail = new MailMessage(sFrom,sTo);
MyMail.Subject = sSubject;
MyMail.Body = sBody;
//MyMail.CC = sCc; // if (sBodyEncoding== Encoding.UTF7.EncodingName)
// MyMail.BodyEncoding = Encoding.UTF7;
// else if (sBodyEncoding== Encoding.UTF8.EncodingName)
// MyMail.BodyEncoding = Encoding.UTF8;
// else
// MyMail.BodyEncoding = Encoding.ASCII; MyMail.IsBodyHtml = isBodyHtml;
MyMail.Priority = mailPriority; try
{
SmtpClient smtpClient=new SmtpClient();
smtpClient.Credentials = new System.Net.NetworkCredential(sMailServerUserName, sMailServerUserPassword);
smtpClient.Host=sMailServer;
if (SmtpServerPort > 0) smtpClient.Port = SmtpServerPort;
smtpClient.Send(MyMail);
}
catch (Exception ee)
{
retValue.HasError = true;
retValue.Message = "发送邮件不成功,可能是因为邮件目标地址不存在!详细错误信息是:" + ee.Message;
}
return retValue;
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Net;public partial class sendmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
string s_from = "[email protected]";
string s_to = "TextBox1.Text";
string pwd = TextBox2.Text; int i = s_from.IndexOf("@");
string username = s_from.Substring(0, i); MailAddress from = new MailAddress(s_from);
MailAddress to = new MailAddress(s_to);
MailMessage mailobj = new MailMessage(from, to);
mailobj.Subject = "aaa";
mailobj.Body = "aaa";
mailobj.IsBodyHtml = true;
mailobj.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
mailobj.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient("smtp.163.com");
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(username, pwd);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; try
{
smtp.Send(mailobj);
Response.Write("ok!"); }
catch
{
Response.Write("sorry!");
} }}