邮件发送问题
MailMessage Message = new MailMessage();
Message.To = "shans.zhao@waysglobal.com ";
Message.From = "shans_ok@163.com ";
Message.Subject = "test mail ";
Message.Body= "null ";
try
{
SmtpMail.SmtpServer = "mail.waysglobal.com ";
SmtpMail.Send(Message);
return true;
}
catch(System.Web.HttpException ehttp)
{
string err = ehttp.Message;
return false;
}
按照上面的代码,我进行邮件发送时,没有任何问题
但,当我把邮件发送地址(Message.From = "shans_ok@163.com ";)也改为我们公司的邮箱(如:roman.luo@waysglobal.com)时,就会出现错误. 错误提示为:未能访问 "CDO.Message "对象.
请问,我该如何解决,以实现用公司内部的邮箱发送到公司内不的员工邮箱中去.
注意:我们公司的邮箱服务器(mail.waysglobal.com)是服务商提供的.
[解决办法]
你看看是不是提供商给的协议不一样的缘故阿?
[解决办法]
可能是编码 问题
[解决办法]
aspx
--------------------------
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "MyMail.aspx.cs " Inherits= "MyMail " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<div style= "text-align: center ">
<table style= "z-index: 100; left: 233px; width: 530px; position: absolute; top: 55px;
height: 347px ">
<tr>
<td colspan= "2 ">
</td>
</tr>
<tr>
<td style= "width: 100px ">
发送到: </td>
<td style= "width: 100px ">
<asp:TextBox ID= "TxtTo " runat= "server " Style= "position: static " Width= "245px "> </asp:TextBox> </td>
</tr>
<tr>
<td style= "width: 100px ">
来自: </td>
<td style= "width: 100px ">
<asp:TextBox ID= "TxtFrom " runat= "server " Style= "position: static " Width= "243px "> </asp:TextBox> </td>
</tr>
<tr>
<td style= "width: 100px ">
标题: </td>
<td style= "width: 100px ">
<asp:TextBox ID= "TxtTitle " runat= "server " Style= "position: static " Width= "245px "> </asp:TextBox>
</td>
</tr>
<tr>
<td style= "width: 100px ">
内容: </td>
<td style= "width: 100px ">
<asp:TextBox ID= "TxtContent " runat= "server " Style= "position: static " Width= "245px "> </asp:TextBox>
</td>
</tr>
<tr>
<td style= "width: 100px ">
附件: </td>
<td style= "width: 100px ">
<asp:FileUpload ID= "File " runat= "server " Style= "position: static " Width= "324px "/>
</td>
</tr>
<tr>
<td style= "width: 100px ">
用户名: </td>
<td style= "width: 100px ">
<asp:TextBox ID= "TxtUserName " runat= "server " Style= "position: static " Width= "245px "> </asp:TextBox>
</td>
</tr>
<tr>
<td style= "width: 100px ">
密码: </td>
<td style= "width: 100px ">
<asp:TextBox ID= "TxtPassWord " runat= "server " Style= "position: static " Width= "245px "> </asp:TextBox>
</td>
</tr>
<tr>
<td style= "width: 100px ">
邮件服务器: </td>
<td style= "width: 100px ">
<asp:TextBox ID= "TxtServerName " runat= "server " Style= "position: static " Width= "245px "> </asp:TextBox>
</td>
</tr>
<tr>
<td colspan= "2 ">
<asp:Button ID= "BtnSendMail " runat= "server " Style= "position: static " Text= "发送邮件 "
Width= "150px " OnClick= "BtnSendMail_Click " /> </td>
</tr>
</table>
<asp:Label ID= "LabMessage " runat= "server " Style= "z-index: 101; left: 372px; position: absolute;
top: 410px " Width= "230px "> </asp:Label>
</div>
</div>
</form>
</body>
</html>
--------------------------
cs
--------------------------
using System;
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.Web.Mail;
public partial class MyMail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnSendMail_Click(object sender, EventArgs e)
{
try
{
SendMail(TxtFrom.Text, TxtTo.Text, TxtTitle.Text, TxtContent.Text, File.PostedFile.FileName, TxtUserName.Text, TxtPassWord.Text, TxtServerName.Text);
Response.Clear();
Response.Write( "邮件发送成功! <a href=\ "javascript:location.href= 'MyMail.aspx '\ "> 返回 </a> ");
Response.End();
}
catch (Exception ex)
{
//Response.Write( " <script> alert(\ " "+ex.Message+ "\ "); </script> ");
//throw new Exception(ex.Message,ex);
LabMessage.Text = ex.Message;
}
}
private void SendMail(string MailFrom, string MailTo, string MailTitle, string MailContent, string MailFile, string UserName, string PassWord, string MailServer)
{
MailMessage mailObj = new MailMessage();
mailObj.From = MailFrom; //来自
mailObj.To = MailTo; //发送到
mailObj.Subject = MailTitle; //邮件标题
mailObj.Body = MailContent; //邮件内容
mailObj.BodyFormat = MailFormat.Html;
mailObj.Priority = MailPriority.High;
mailObj.Attachments.Add(new MailAttachment(MailFile)); //邮件附件
mailObj.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ", "1 ");
mailObj.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername ", UserName); //帐号名
mailObj.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword ", PassWord); //密码
SmtpMail.SmtpServer = MailServer; //邮件服务器
SmtpMail.Send(mailObj);
}
}
----------------------
[解决办法]
帮顶
[解决办法]
SmtpClient client = new SmtpClient();
//输入IP地址,即mail.waysglobal.com的IP,估计用server名也可以
client.Host = "ip地址 ";
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = true;
//下面的这句很重要,没有用户名和密码,只能发本邮件服务器用户
//加上下面的,可以发所有的地址
client.Credentials = new System.Net.NetworkCredential( "admin@waysglobal.com ", "111 "); //输入帐号和密码,你的那个CDO是加密用的吧,我也没有试过
client.Send(mailMsg);