请问为什么我用SmtpMail和MailMessage不能发邮件.

honjo 2004-05-04 08:42:35
代码如下:
MailMessage msgMail = new MailMessage();
msgMail.To = honjo@sina.com; //邮件接受者
msgMail.From = "hong102@21cn.com";
msgMail.Subject = "您的定单信息。";

msgMail.BodyFormat = MailFormat.Html;
string strBody = "<html><body>Test mail messages!!!</body></html>"
msgMail.Body = strBody;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(msgMail);

没有错误产生,但honjo@sina.com就是收不到邮件,
我用的是window2000server的IIS自带的smtp,服务已启,但会在\Inetpub\mailroot\Queue\下有邮件的文件,但就是不会向目标邮件发出去
妈的,搞了一天了,没搞出来,还望哪位有经验的赐教啊.
...全文
270 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
good_cyg 2004-08-11
  • 打赏
  • 举报
回复
同意楼上的 你要用base64写个验证过程 要不你的邮件是发不出
ylh1223 2004-08-03
  • 打赏
  • 举报
回复
原因事smtp服务器需要身分验证,发送邮件之前添加如下代码:
email.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
email.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","用户帐号");
email.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","用户密码");
marvelstack 2004-07-31
  • 打赏
  • 举报
回复
参考
http://blog.csdn.net/zhzuo/archive/2004/07/12/39459.aspx
xw123 2004-07-15
  • 打赏
  • 举报
回复
代吗(包括邮箱的设置 stmp 的设置)没有错误的话你就现卸载组件 再重新安装 或者换台机子试试!
spidertan 2004-07-15
  • 打赏
  • 举报
回复
好像跟你的outlook配置也有关系,主要是邮件发送格式,sql server中发送邮件时,一般要求我把outlook的邮件发送格式设置为“纯文本”,所以我想这个问题是不是也这样
cgmx 2004-07-14
  • 打赏
  • 举报
回复
支持的.但要有权限.
就是邮件服务器(exchange等,或比如163的smtp服务器)要对你的服务器进行授权.准许你通过smtp
lofa 2004-07-14
  • 打赏
  • 举报
回复
。net里面带的好像不支持Smtp服务器要求身份认证的情况,换OutLook的组件发送就能有这个功能。
chhwang 2004-07-09
  • 打赏
  • 举报
回复
有没有添加对System.Web.dll的引用啊
ITsoftware 2004-07-07
  • 打赏
  • 举报
回复
可能是瑞星的问题,关闭邮件发送监控就好了,这个问题曾经困扰了我好久
hfwang009 2004-06-09
  • 打赏
  • 举报
回复
同意,应该是楼主的smtpserver没有配置好
长弓三石 2004-06-09
  • 打赏
  • 举报
回复
搂住可以先用别的smtpserver试试,看看是不是你的smtpserver本身的问题
AngelGavin 2004-06-09
  • 打赏
  • 举报
回复
我发出去了
楼主还不行么?
honjo 2004-05-04
  • 打赏
  • 举报
回复
我是asp.net的webform一样吗?
fds2003 2004-05-04
  • 打赏
  • 举报
回复
给个例子你看看!
fds2003 2004-05-04
  • 打赏
  • 举报
回复
this.label3.Location = new System.Drawing.Point(16, 64);
this.label3.Name = "label3";
this.label3.TabIndex = 2;
this.label3.Text = "From:";
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 88);
this.label4.Name = "label4";
this.label4.TabIndex = 3;
this.label4.Text = "Subject:";
//
// txtSmtpServer
//
this.txtSmtpServer.Location = new System.Drawing.Point(104, 16);
this.txtSmtpServer.Name = "txtSmtpServer";
this.txtSmtpServer.Size = new System.Drawing.Size(176, 20);
this.txtSmtpServer.TabIndex = 4;
this.txtSmtpServer.Text = "";
//
// txtRecipient
//
this.txtRecipient.Location = new System.Drawing.Point(104, 40);
this.txtRecipient.Name = "txtRecipient";
this.txtRecipient.Size = new System.Drawing.Size(176, 20);
this.txtRecipient.TabIndex = 5;
this.txtRecipient.Text = "";
//
// txtFrom
//
this.txtFrom.Location = new System.Drawing.Point(104, 64);
this.txtFrom.Name = "txtFrom";
this.txtFrom.Size = new System.Drawing.Size(176, 20);
this.txtFrom.TabIndex = 6;
this.txtFrom.Text = "";
//
// txtSubject
//
this.txtSubject.Location = new System.Drawing.Point(104, 88);
this.txtSubject.Name = "txtSubject";
this.txtSubject.Size = new System.Drawing.Size(176, 20);
this.txtSubject.TabIndex = 7;
this.txtSubject.Text = "";
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 120);
this.label5.Name = "label5";
this.label5.TabIndex = 8;
this.label5.Text = "Message:";
//
// txtMessage
//
this.txtMessage.Location = new System.Drawing.Point(16, 136);
this.txtMessage.Multiline = true;
this.txtMessage.Name = "txtMessage";
this.txtMessage.Size = new System.Drawing.Size(264, 128);
this.txtMessage.TabIndex = 9;
this.txtMessage.Text = "";
//
// label6
//
this.label6.Location = new System.Drawing.Point(16, 280);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(112, 23);
this.label6.TabIndex = 10;
this.label6.Text = "Attachment Location:";
//
// txtAttachment
//
this.txtAttachment.Location = new System.Drawing.Point(128, 280);
this.txtAttachment.Name = "txtAttachment";
this.txtAttachment.Size = new System.Drawing.Size(152, 20);
this.txtAttachment.TabIndex = 11;
this.txtAttachment.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(200, 312);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 32);
this.button1.TabIndex = 12;
this.button1.Text = "Send";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 357);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.txtAttachment,
this.label6,
this.txtMessage,
this.label5,
this.txtSubject,
this.txtFrom,
this.txtRecipient,
this.txtSmtpServer,
this.label4,
this.label3,
this.label2,
this.label1});
this.Name = "Form1";
this.Text = "SMTP Mail Example";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
// Create mail message
MailMessage email = new MailMessage();

// Set message parameters
email.From = txtFrom.Text;
email.To = txtRecipient.Text;
email.Subject = txtSubject.Text;
email.BodyFormat = System.Web.Mail.MailFormat.Text;
email.Body = txtMessage.Text;

// Add attachment
email.Attachments.Add(new MailAttachment(txtAttachment.Text,
MailEncoding.Base64));

// Set SMTP server
SmtpMail.SmtpServer = txtSmtpServer.Text;

// Now send message
SmtpMail.Send(email);
}
}
}
fds2003 2004-05-04
  • 打赏
  • 举报
回复
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Web.Mail;

namespace SmtpClient
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtSmtpServer;
private System.Windows.Forms.TextBox txtRecipient;
private System.Windows.Forms.TextBox txtFrom;
private System.Windows.Forms.TextBox txtSubject;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtMessage;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox txtAttachment;
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.txtSmtpServer = new System.Windows.Forms.TextBox();
this.txtRecipient = new System.Windows.Forms.TextBox();
this.txtFrom = new System.Windows.Forms.TextBox();
this.txtSubject = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.txtMessage = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.txtAttachment = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "SMTP Server:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 40);
this.label2.Name = "label2";
this.label2.TabIndex = 1;
this.label2.Text = "Recipient:";
//
// label3
//
honjo 2004-05-04
  • 打赏
  • 举报
回复
楼上这位大哥,我改了也不行,文件还是在\Inetpub\mailroot\Queue\这个文件夹里,
没有发出去,真是气死人了,
请问,是不是用这个东东发mail要设置其它什么地方呢,
我看了很多其它人的示例,好像都是这样的,为什么唯独我的就不行呢?
郁闷啊...郁闷啊...郁闷啊...郁闷啊...
fds2003 2004-05-04
  • 打赏
  • 举报
回复
msgMail.To="honjo@sina.com"是这么样的!
honjo 2004-05-04
  • 打赏
  • 举报
回复
还是发不出去啊,
leogigi 2004-05-04
  • 打赏
  • 举报
回复
SMTP的属性你设置了吗?
作为本地邮件服务器发送邮件你需要设置一些属性

首先,右击"默认SMTP虚拟服务器"
接着设置属性如下:  
  “访问”选项卡中设置访问权限。单击“身份验证”,选择“匿名访问”,表示任何用户都可以发送,其他两项不用选择;单击“连接控制”中的“连接”和“中段限制”中的“中断”,选中“仅以下列表除外”,表示可以许接入所有用户的访问。

  “邮件”选项卡中设置邮件传输条件及限制,“限制邮件大小为”等四个选项可以使用默认值,无须更改;

  “将未传递报告的副本发送到”可将发送不成功的邮件返回发件人,并且写明不成功的原因;“死信目录”设置没有发送成功的邮件被存放的位置。

  “传输”选项中设置邮件传递时间,这里不用修改,使用默认值;“LDAP路由”选项用来指定服务器使用的目录服务器标识和属性,这里也不用启动它。

  “安全”选项中设置使用发送服务器的有权用户,默认用户是“Administrators”,你可以单击“添加”添加使用用户。

17,747

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧