本文介绍了错误是SmtpMail.Send(objMail)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在下面的代码中给出了SmtpMail.Send(objMail)错误?

Why the error is given SmtpMail.Send(objMail) in the below code?

<%@ Page Language="VB" EnableSessionState="False" EnableViewState="False" Trace="False" Debug="True"%>
<%@ Import Namespace="System.Web.Mail" %>
<script  runat="server">
Sub Page_Load(Sender as Object, E as EventArgs)
    If Page.IsPostBack Then
        lblResponse.Text = "Your email has been sent."
    End If
End Sub
     
Sub btn_Click(sender as Object, e as System.EventArgs)
  If  Request.Form("Email") <> "" Then
    Dim objMail As New MailMessage()
    objMail.From = "[email protected]"
    objMail.To = Request.Form("Email")
    objMail.Subject = Request.Form("Subject")
    objMail.Body = Request.Form("Message")
    objMail.BodyFormat = MailFormat.Text
    SmtpMail.SmtpServer = " smtp.kamnatrust.com"
    SmtpMail.Send(objMail)
  Else
    lblResponse.Text = "Please enter an email address."
  End If
End Sub


</script>
<html>
<head>
<style>
.main {font-family:Verdana; font-size:12px;}
.title {font-family:Verdana; font-size:18px; font-weight:bold;}
</style>
</head>
<body>
<span class="title" align="center">Send email from  
an ASP.NET page</span>

<br><br><asp:Label class="main" id="lblResponse" runat="server"/>
 
<form method="POST" name="MainForm"  runat="server">
<table>
  <tr>
    <td class="main" align="right">Email:</td> <br>
    <td class="main"><input type="text" class="main" name="Email" value=""></td>
  </br></tr>
  <tr>
    <td class="main" align="right"> 
    Subject:</td>
    <td class="main"><input type="text" class="main" name="Subject" value=""></td>
  </tr>
  <tr>
    <td class="main" align="right" valign="top">Message:</td>
    <td class="main"><textarea name="Message" cols="50" rows="8"></textarea></td>
  </tr>

  <tr>
    <td class="main"> </td>
    <td class="main"><input type="Submit" id="btnSubmit"  önServerClick="btn_Click" value="Send"  runat="server" /></td>
  </tr>
</table>
</form>
</body>
</html></br></br>

推荐答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using System.Text;
using System.Data.SqlClient;
using System.Web.Mail;
using System.Net;
using System.Net.Mail;
using System.Drawing;
using System.IO;


  System.Net.Mail.MailMessage obj = new System.Net.Mail.MailMessage();

  SmtpClient serverobj = new SmtpClient();
            serverobj.Credentials = new NetworkCredential("[email protected]", "archuanil");
            serverobj.Port = 587;
            serverobj.Host = "smtp.gmail.com";
            serverobj.EnableSsl = false;
            obj = new System.Net.Mail.MailMessage();
            obj.From = new MailAddress("[email protected]", "AgileLearning.com", System.Text.Encoding.UTF8);
            obj.To.Add(ASPxtxtToUser.Text);
            obj.CC.Add(ASPxTexttoCc.Text);
            obj.Priority = System.Net.Mail.MailPriority.High;
            obj.Subject = txtSubject.Text;
            string date = DateTime.Now.ToString();
            obj.Body = ASPxMemo1.Text;
            serverobj.Send(obj);
            lblsend.Text = "Your Message Send Sucessfully";


在按钮代码中尝试此操作.


问候,

Anilkumar.D


Try this in Button Code.


Regards,

Anilkumar.D


这篇关于错误是SmtpMail.Send(objMail)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 12:33