要导入system.web.mail命名空间SmtpMail.SmtpServer = "127.0.0.1"; 这句也有问题。以下是我用vb.net写的。运行正常 <%@ import namespace="system.web.mail"%> <HTML> <body> asp.net e-mail 发送程序 <form runat="server"> <table border="1"> <tr> <td>收件人:</td> <td><asp:textbox ID="mailto" size="40" Runat="server" /></td> </tr> <tr> <td>发件人:</td> <td><asp:textbox ID="mailfrom" size="40" Runat="server" /></td> </tr> <tr> <td>主题:</td> <td><asp:textbox ID="mailsubject" size="40" Runat="server" /></td> </tr> <tr> <td>内容:</td> <td><asp:textbox ID="mailbody" textmode="MultiLine" Rows="8" cols="60" Runat="server" /></td> </tr> <tr> <td> <asp:radiobuttonlist ID="format" Runat="server" repeatdirection="horizontal" repeatcolumns="2"> <asp:listitem Selected>HTML格式</asp:listitem> <asp:listitem>纯文本格式</asp:listitem> </asp:radiobuttonlist> </td> </tr> </table> <asp:button Runat="server" Text="发送" OnClick="button_click" id="Button1" /> </form> <asp:label ID="msg" Runat="server" ForeColor="red" /> <script language="vb" runat="server"> sub button_click(sender as object, e as eventargs) dim mail as mailmessage = new mailmessage mail.to = mailto.text mail.from = mailfrom.text mail.subject = mailsubject.text if format.selecteditem.text="纯文本格式" then mail.bodyformat = mailformat.text else mail.bodyformat = mailformat.html end if 'mail.bodyformat=mailformat.text mail.body = mailbody.text
on error resume next smtpmail.smtpserver = "smtp.joysos.com" smtpmail.send(mail)
if err.number <> 0 then msg.text = err.description else msg.text="邮件已成功发送" end if end sub </script> </body> </HTML>
能不能给我C#的winform程序啊? 而且你的跟我的也大同小异啊!
而且把你的SMTP 放上去以后,告诉我CDO不能访问啊!~另外谁能告诉我 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "[email protected]"); //set your username here mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456"); //set your password here 这段代码是用来验证SMTP服务器的还是发件人信箱的呢?
这句也有问题。以下是我用vb.net写的。运行正常
<%@ import namespace="system.web.mail"%>
<HTML>
<body>
asp.net e-mail 发送程序
<form runat="server">
<table border="1">
<tr>
<td>收件人:</td>
<td><asp:textbox ID="mailto" size="40" Runat="server" /></td>
</tr>
<tr>
<td>发件人:</td>
<td><asp:textbox ID="mailfrom" size="40" Runat="server" /></td>
</tr>
<tr>
<td>主题:</td>
<td><asp:textbox ID="mailsubject" size="40" Runat="server" /></td>
</tr>
<tr>
<td>内容:</td>
<td><asp:textbox ID="mailbody" textmode="MultiLine" Rows="8" cols="60" Runat="server" /></td>
</tr>
<tr>
<td>
<asp:radiobuttonlist ID="format" Runat="server" repeatdirection="horizontal" repeatcolumns="2">
<asp:listitem Selected>HTML格式</asp:listitem>
<asp:listitem>纯文本格式</asp:listitem>
</asp:radiobuttonlist>
</td>
</tr>
</table>
<asp:button Runat="server" Text="发送" OnClick="button_click" id="Button1" />
</form>
<asp:label ID="msg" Runat="server" ForeColor="red" />
<script language="vb" runat="server">
sub button_click(sender as object, e as eventargs)
dim mail as mailmessage = new mailmessage
mail.to = mailto.text
mail.from = mailfrom.text
mail.subject = mailsubject.text
if format.selecteditem.text="纯文本格式" then
mail.bodyformat = mailformat.text
else
mail.bodyformat = mailformat.html
end if
'mail.bodyformat=mailformat.text
mail.body = mailbody.text
on error resume next
smtpmail.smtpserver = "smtp.joysos.com"
smtpmail.send(mail)
if err.number <> 0 then
msg.text = err.description
else
msg.text="邮件已成功发送"
end if
end sub
</script>
</body>
</HTML>
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "[email protected]"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456"); //set your password here
这段代码是用来验证SMTP服务器的还是发件人信箱的呢?