读书人

小弟我想问一个有关问题 如何用ASP自动

发布时间: 2012-01-19 20:57:58 作者: rapoo

大虾 我想问一个问题 怎么用ASP自动发送邮件
我想做个网页 在上面点击审核按钮
会自动发送一个邮件给某个的人!怎么实现这个呢?


[解决办法]
邮件要有相应的接口吧

[解决办法]
?
http://blog.joycode.com/ghj/archive/2005/10/01/64458.aspx

http://www.aspxboy.com/490/default.aspx
[解决办法]
去看看System.Web.Mail 包的SmtpMail
这是MSDN的例子

using System;
using System.Web.Mail;

namespace SendMail
{
class usage
{
public void DisplayUsage()
{
Console.WriteLine( "Usage SendMail.exe <to> <from> <subject> <body> ");
Console.WriteLine( " <to> the addresses of the email recipients ");
Console.WriteLine( " <from> your email address ");
Console.WriteLine( " <subject> subject of your email ");
Console.WriteLine( " <body> the text of the email ");
Console.WriteLine( "Example: ");
Console.WriteLine( "SendMail.exe SomeOne@Contoso.com;SomeOther@Contoso.com Me@contoso.com Hi hello ");
}
}


class Start
{
// The main entry point for the application.
[STAThread]
static void Main(string[] args)
{
try
{
try
{
MailMessage Message = new MailMessage();
Message.To = args[0];
Message.From = args[1];
Message.Subject = args[2];
Message.Body = args[3];

try
{
SmtpMail.SmtpServer = "your mail server name goes here ";
SmtpMail.Send(Message);
}
catch(System.Web.HttpException ehttp)
{
Console.WriteLine( "{0} ", ehttp.Message);
Console.WriteLine( "Here is the full error message output ");
Console.Write( "{0} ", ehttp.ToString());
}
}
catch(IndexOutOfRangeException)
{
usage use = new usage();
use.DisplayUsage();
}
}
catch(System.Exception e)
{
Console.WriteLine( "Unknown Exception occurred {0} ", e.Message);
Console.WriteLine( "Here is the Full Message output ");
Console.WriteLine( "{0} ", e.ToString());
}
}
}
}

[解决办法]
学习来了
[解决办法]
using System;
using System.Web.Mail;

namespace LiveMessage.Common
{
/// <summary>
/// SendMail 的摘要说明。
/// </summary>
public class SendMail
{
public SendMail()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public static bool sendMail(string from,string to,string subject,string body,string smtpaccountname,string sendusername,string sendpassword,string smtpServer)
{
try
{
MailMessage mm=new MailMessage();
mm.BodyFormat=MailFormat.Html;
mm.From=from;
mm.To=to;


mm.BodyEncoding=System.Text.Encoding.GetEncoding(936);
mm.Subject=subject;
mm.Body=body;
mm.Fields[ "http://schemas.microsoft.com/cdo/configuration/sendusing "] = 2;
mm.Fields[ "http://schemas.microsoft.com/cdo/configuration/smtpaccountname "] = smtpaccountname;
mm.Fields[ "http://schemas.microsoft.com/cdo/configuration/sendusername "] = sendusername;//验证账号:发送者邮箱账号
mm.Fields[ "http://schemas.microsoft.com/cdo/configuration/sendpassword "] = sendpassword; //验证密码:发送者邮箱密码
mm.Fields[ "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate "] = 1; //验证级别0,1,2
mm.Fields[ "http://schemas.microsoft.com/cdo/configuration/languagecode "] = 0x0804;//语言代码
System.Web.Mail.SmtpMail.SmtpServer=smtpServer;//上句和这句重着,这句可以替代上句
System.Web.Mail.SmtpMail.Send(mm);
return true;
}
catch
{
return false;
}
}
}
}

读书人网 >C#

热点推荐