关于Mail发送的问题,紧急求助,郁闷好久了!

azure711 2005-12-23 12:41:01
mailToSend.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
SmtpMail.SmtpServer = Me.mAccount.SMTPHost
SmtpMail.Send(mailToSend)
.......
抛出异常“无法访问CDO....”
在网上寻觅了好久,众说风云各抒己见,但是始终出现这样的问题(特列:在某些机子上能发某些就是异常)。这是我的郁闷之处,难道和系统、开发环境有关吗?那么相关在何处呢?
请大家各抒己见,谢谢了!
...全文
401 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
生活真美好 2005-12-26
  • 打赏
  • 举报
回复
查一下是不是防火墙的设置太高了。
生活真美好 2005-12-26
  • 打赏
  • 举报
回复
我试过没有问题呀,“无法访问CDO....”为外网无法访问时才有。
azure711 2005-12-24
  • 打赏
  • 举报
回复
you should have enough privilege
这里提到的足够的权限是指哪些权限呢?
kisshere 2005-12-23
  • 打赏
  • 举报
回复
在某些机子上能发某些就是异常

because some computers have installed smtp service, so it is ok. but some did not, so there is exception.

If you use MailMessage class, you should have enough privilege. else you can use jmail or socket to send email.
yzg100 2005-12-23
  • 打赏
  • 举报
回复
this.MessageTextBox.Multiline = true;
this.MessageTextBox.Name = "MessageTextBox";
this.MessageTextBox.Size = new System.Drawing.Size(342, 164);
this.MessageTextBox.TabIndex = 6;
this.MessageTextBox.Text = "";
this.ExitButton.BackColor = System.Drawing.Color.RosyBrown;
this.ExitButton.Location = new System.Drawing.Point(213, 412);
this.ExitButton.Name = "ExitButton";
this.ExitButton.Size = new System.Drawing.Size(77, 26);
this.ExitButton.TabIndex = 9;
this.ExitButton.Text = "退 出";
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(47, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(33, 16);
this.label1.TabIndex = 2;
this.label1.Text = "发自:";
this.ToTextBox.Location = new System.Drawing.Point(102, 57);
this.ToTextBox.Name = "ToTextBox";
this.ToTextBox.Size = new System.Drawing.Size(256, 20);
this.ToTextBox.TabIndex = 1;
this.ToTextBox.Text = "";
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label3.Location = new System.Drawing.Point(47, 163);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(33, 16);
this.label3.TabIndex = 2;
this.label3.Text = "主题:";
this.BrowseButton.Location = new System.Drawing.Point(298, 198);
this.BrowseButton.Name = "BrowseButton";
this.BrowseButton.Size = new System.Drawing.Size(60, 26);
this.BrowseButton.TabIndex = 7;
this.BrowseButton.Text = "浏览...";
this.BrowseButton.Click += new System.EventHandler(this.BrowseButton_Click);
this.SubjectTextBox.Location = new System.Drawing.Point(102, 163);
this.SubjectTextBox.Name = "SubjectTextBox";
this.SubjectTextBox.Size = new System.Drawing.Size(256, 20);
this.SubjectTextBox.TabIndex = 4;
this.SubjectTextBox.Text = "";
this.SendButton.BackColor = System.Drawing.Color.Aqua;
this.SendButton.Location = new System.Drawing.Point(68, 412);
this.SendButton.Name = "SendButton";
this.SendButton.Size = new System.Drawing.Size(77, 26);
this.SendButton.TabIndex = 8;
this.SendButton.Text = "发 送";
this.SendButton.Click += new System.EventHandler(this.SendButton_Click);
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(47, 59);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(33, 16);
this.label2.TabIndex = 2;
this.label2.Text = "发往:";
this.AttachmentTextBox.Location = new System.Drawing.Point(102, 198);
this.AttachmentTextBox.Name = "AttachmentTextBox";
this.AttachmentTextBox.Size = new System.Drawing.Size(180, 20);
this.AttachmentTextBox.TabIndex = 5;
this.AttachmentTextBox.Text = "";
this.FromTextBox.Location = new System.Drawing.Point(102, 18);
this.FromTextBox.Name = "FromTextBox";
this.FromTextBox.Size = new System.Drawing.Size(256, 20);
this.FromTextBox.TabIndex = 0;
this.FromTextBox.Text = "";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(366, 442);
this.Controls.Add(this.BrowseButton);
this.Controls.Add(this.AttachmentTextBox);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.BCCTextBox);
this.Controls.Add(this.CCLabel);
this.Controls.Add(this.CCTextBox);
this.Controls.Add(this.ExitButton);
this.Controls.Add(this.SendButton);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.SubjectTextBox);
this.Controls.Add(this.ToTextBox);
this.Controls.Add(this.FromTextBox);
this.Controls.Add(this.MessageTextBox);
this.Name = "Form1";
this.Text = "发送邮件";
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void SendButton_Click(object sender, System.EventArgs e)
{
try
{
MailMessage aMessage = new MailMessage();
aMessage.From = FromTextBox.Text;
aMessage.To = ToTextBox.Text;
aMessage.Cc = CCTextBox.Text;
aMessage.Bcc = BCCTextBox.Text;
aMessage.Subject = SubjectTextBox.Text;
aMessage.Body = MessageTextBox.Text;
if (AttachmentTextBox.Text.Length > 0)
aMessage.Attachments.Add(new MailAttachment(AttachmentTextBox.Text, MailEncoding.Base64));

SmtpMail.Send(aMessage);

MessageBox.Show("邮件发送成功!");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}

private void ExitButton_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void BrowseButton_Click(object sender, System.EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
AttachmentTextBox.Text = this.openFileDialog1.FileName;
}
}

}
}
yzg100 2005-12-23
  • 打赏
  • 举报
回复
刚好我这有个例子,不知从那找的了。做过测试,不过163的邮箱没收到,Gmail收到了。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Web;
using System.Web.Mail;

namespace EMailer
{

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.Button SendButton;
private System.Windows.Forms.Button ExitButton;
private System.Windows.Forms.TextBox FromTextBox;
private System.Windows.Forms.TextBox ToTextBox;
private System.Windows.Forms.TextBox SubjectTextBox;
private System.Windows.Forms.TextBox MessageTextBox;
private System.Windows.Forms.TextBox CCTextBox;
private System.Windows.Forms.Label CCLabel;
private System.Windows.Forms.TextBox BCCTextBox;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button BrowseButton;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.TextBox AttachmentTextBox;

private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

/// <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

private void InitializeComponent()
{
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.CCTextBox = new System.Windows.Forms.TextBox();
this.CCLabel = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.BCCTextBox = new System.Windows.Forms.TextBox();
this.MessageTextBox = new System.Windows.Forms.TextBox();
this.ExitButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.ToTextBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.BrowseButton = new System.Windows.Forms.Button();
this.SubjectTextBox = new System.Windows.Forms.TextBox();
this.SendButton = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.AttachmentTextBox = new System.Windows.Forms.TextBox();
this.FromTextBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.openFileDialog1.Title = "请选择邮件附件";
this.CCTextBox.Location = new System.Drawing.Point(102, 95);
this.CCTextBox.Name = "CCTextBox";
this.CCTextBox.Size = new System.Drawing.Size(256, 20);
this.CCTextBox.TabIndex = 2;
this.CCTextBox.Text = "";
this.CCLabel.AutoSize = true;
this.CCLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.CCLabel.Location = new System.Drawing.Point(47, 97);
this.CCLabel.Name = "CCLabel";
this.CCLabel.Size = new System.Drawing.Size(33, 16);
this.CCLabel.TabIndex = 2;
this.CCLabel.Text = "抄送:";
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label4.Location = new System.Drawing.Point(47, 126);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(33, 16);
this.label4.TabIndex = 2;
this.label4.Text = "密送:";
this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label5.Location = new System.Drawing.Point(47, 201);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(33, 16);
this.label5.TabIndex = 2;
this.label5.Text = "附件:";
this.BCCTextBox.Location = new System.Drawing.Point(102, 129);
this.BCCTextBox.Name = "BCCTextBox";
this.BCCTextBox.Size = new System.Drawing.Size(256, 20);
this.BCCTextBox.TabIndex = 3;
this.BCCTextBox.Text = "";
this.MessageTextBox.Location = new System.Drawing.Point(8, 232);
lhz888 2005-12-23
  • 打赏
  • 举报
回复
Public Function send() As Boolean
Dim mailmsg As New MailMessage
SmtpMail.SmtpServer = mailserver
mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", auth)

mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", user)
mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pass)

mailmsg.Cc = ""
mailmsg.From = sender
mailmsg.To = receiver
mailmsg.Subject = subject
mailmsg.BodyEncoding = System.Text.Encoding.Default
'mailmsg.BodyFormat = format
If Me.isHtml Then
mailmsg.BodyFormat = System.Web.Mail.MailFormat.Html
Else
mailmsg.BodyFormat = System.Web.Mail.MailFormat.Text
End If


mailmsg.Body = content
If attachment <> "" Then
mailmsg.Attachments.Add(New MailAttachment(attachment))
End If


Try

SmtpMail.Send(mailmsg)
Return True

Catch ex As Exception
Console.Write(ex.Message)
Return False

End Try
End Function


End Class
End Namespace
qmail03 2005-12-23
  • 打赏
  • 举报
回复
建议用POWERTCP MAIL控件,发送接受都没有问题

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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