private void Button1_Click(object sender, System.EventArgs e)
{
MailMessage mymail = new MailMessage();
mymail.From = From.Text;
mymail.To = To.Text;
mymail.Subject = Subject.Text;
mymail.Body = Body.Text;
mymail.Fields.Add try
{
SmtpMail.Send(mymail);
msg.Text = "发送成功!!";
}
catch(System.Exception E)
{
msg.Text = E.ToString();
}
}
-------------------------------------------------------------------
出错信息:
System.Web.HttpException: 未能访问“CDO.Message”对象。 ---> System.Reflection.TargetInvocationException: 调用的目标发生了异常。 --->
{
MailMessage mymail = new MailMessage();
mymail.From = From.Text;
mymail.To = To.Text;
mymail.Subject = Subject.Text;
mymail.Body = Body.Text;
mymail.Fields.Add try
{
SmtpMail.Send(mymail);
msg.Text = "发送成功!!";
}
catch(System.Exception E)
{
msg.Text = E.ToString();
}
}
-------------------------------------------------------------------
出错信息:
System.Web.HttpException: 未能访问“CDO.Message”对象。 ---> System.Reflection.TargetInvocationException: 调用的目标发生了异常。 --->
解决方案 »
- 紧急求助一个xml的显示。。。
- excel 导入数据库 3.48716000018E+20 。。。。
- 网站发布后上传到服务器以后打开出现错误!!急急急急急急 求高手帮忙解决!
- 将.net代码切成HTML源码
- JavaScrip的函数里,怎么应用后台的文本框的Text
- 郁闷 这是什么问题啊。JJ都变形了
- 急救,一个关于Cookie过期的问题
- 想做个用在自已的网页上就可以注册申请的电子邮件地址,给你思路
- 在ASP.net编程中,如何引用自己写的组件?
- 网页之间传递数据出现问题了,很迷惑................
- 如何将string类型转换为DateTime,money类型?
- 用户控件(c#)
try
{
MailMessage Objmail = new MailMessage();
Objmail.To = mail.to;
Objmail.From = mail.from;
Objmail.Bcc = mail.bcc;
Objmail.Cc = mail.cc;
Objmail.Subject = mail.subject;
Objmail.Body = mail.body;
if(mail.attfile!="")
{
string sAttach = mail.attfile.ToString();
char[] delim = new char[] {','};
foreach (string sSubstr in sAttach.Split(delim))
{
MailAttachment MyAttachment = new MailAttachment(sSubstr);
Objmail.Attachments.Add(MyAttachment);
} }
Objmail.UrlContentBase = "http://www.contoso.com/images";
Objmail.UrlContentLocation = "http://www.contoso.com/images";
Objmail.BodyFormat = MailFormat.Text;
Objmail.Priority = MailPriority.Normal; Objmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
Objmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ""+mail.username+"");
Objmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ""+mail.password+""); SmtpMail.SmtpServer = mail.mailserver;
SmtpMail.Send(Objmail);
UpdateDataBase(sql);
//return true;
}
catch(ThreadInterruptedException e)
{
}
Imports System.Web
Imports System.Web.Mail
Imports System.Collections
Imports System.Data
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.FormsDim mails As New MailMessage()Try
If Me.TextBox2.Text = "" Then
MsgBox("请输入收件人地址", MsgBoxStyle.OKOnly, "提示")
Return
Else End If
If Me.TextBox3.Text = "" Then
MsgBox("请输发收件人地址", MsgBoxStyle.OKOnly, "提示")
Return
End If If Me.TextBox4.Text = "" Then
MsgBox("请输入主题", MsgBoxStyle.OKOnly, "提示")
Return
End If
mails.To = Trim(Me.TextBox2.Text)
mails.From = Trim(Me.TextBox3.Text)
mails.Subject = Trim(Me.TextBox4.Text)
mails.BodyFormat = MailFormat.Html
mails.Priority = MailPriority.High
mails.Body = Trim(Me.TextBox1.Text)
SmtpMail.Send(mails)
MsgBox("发送成功", MsgBoxStyle.OKOnly, "提示")
Catch ex As Exception
MsgBox("发送不成功", MsgBoxStyle.OKOnly, "出错")
End Try
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1"); //basic authentication
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","[email protected]"); //set your username here
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","qwer-123"); //set your password here 可以了,加上这些就可以了!