SmtpMail.Send(msg)中的错误; [英] Error in SmtpMail.Send(msg);

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

问题描述

为什么给出此错误"SendUsing"配置值无效.在此行SmtpMail.Send(msg);?

我的代码在下面

Why this error is given The "SendUsing" configuration value is invalid. in this line SmtpMail.Send(msg);?

My code is given below

<html>
<body>
    <h3>
        Email From ASP.NET</h3>
    <form id="MailForm" method="post" runat="server">
        <asp:Label ID="Label1" Style="left: 100px; position: absolute; top: 100px" runat="server">From:
        </asp:Label>
        <asp:TextBox ID="txtFrom" Style="left: 200px; position: absolute; top: 100px"

          runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="FromValidator1" Style="left: 100px; position: absolute;
            top: 375px" runat="server" ErrorMessage="Please Enter the Email From." Width="200px"

            Height="23px" ControlToValidate="txtFrom"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="FromValidator2" Style="left: 100px; position: absolute;
            top: 400px" runat="server" ErrorMessage="Please Enter a Valid From Email address"

            ControlToValidate="txtFrom" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        <asp:Label ID="Label2" Style="left: 100px; position: absolute; top: 125px" runat="server">To:
        </asp:Label>
        <asp:TextBox ID="txtTo" Style="left: 200px; position: absolute; top: 125px"

          runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="ToValidator1" Style="left: 100px; position: absolute;
            top: 425px" runat="server" ErrorMessage="Please Enter the Email To." Width="200px"

            Height="23px" ControlToValidate="txtTo"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="ToValidator2" Style="left: 100px; position: absolute;
            top: 450px" runat="server" ErrorMessage="Please Enter a Valid To Email address"

            ControlToValidate="txtTo" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        <asp:Label ID="Label3" Style="left: 100px; position: absolute; top: 150px"

          runat="server">Subject</asp:Label>
        <asp:TextBox ID="txtSubject" Style="left: 200px; position: absolute; top: 150px"

            runat="server"></asp:TextBox>
        <asp:Label ID="Label4" Style="left: 100px; position: absolute; top: 175px" runat="server">Mail:
        </asp:Label>
        <textarea runat="server" id="txtContent" style="left: 200px; width: 400px; position: absolute;
            top: 175px; height: 125px" rows="7" cols="24">
                </textarea>
        <asp:Button ID="btnSend" Style="left: 200px; position: absolute; top: 350px" runat="server"

            Text="Send" OnClick="btnSend_Click"></asp:Button>
        <asp:Label ID="lblStatus" Style="left: 250px; position: absolute; top: 350px" runat="server">
        </asp:Label>
    </form>
</body>
</html>





<%@ Import Namespace="System.Web.Mail" %>
<%@ Page Language="C#" Debug="true" %>
<script runat="server">

private void btnSend_Click(object sender, System.EventArgs e)

{
    MailMessage msg = new MailMessage();
    msg.To = txtTo.Text;
    msg.From = txtFrom.Text;
    msg.Subject = txtSubject.Text;
    msg.Body = txtContent.Value;
    lblStatus.Text = "Sending...";
    SmtpMail.Send(msg);
    lblStatus.Text = "Sent email (" + txtSubject.Text + ") to " +txtTo.Text;
}

推荐答案

要发送邮件,您可以将此方法与您的Webmail势能一起使用
to send mail you can use this method with your webmail cardentials
public static Boolean SendingMail(string From, string To, string Subject, string Body)
    {
        
            try
            {
                MailMessage m = new MailMessage("sender@gmail.com", To);
                m.Subject = Subject;
                m.Body = Body;
                m.IsBodyHtml = true;
                m.From = new MailAddress(From);

                m.To.Add(new MailAddress(To));
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "mail.google.com";
              
                NetworkCredential authinfo = new NetworkCredential("sender@gmail.com", "u1234");
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = authinfo;
                smtp.Send(m);
                return true;

               


            }
            catch (Exception ex)
            {
                return false;
            }
        }


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

  SmtpClient serverobj = new SmtpClient();
            serverobj.Credentials = new NetworkCredential("YourEmailId", "YourPassword");
            serverobj.Port = 587;
            serverobj.Host = "smtp.gmail.com";
            serverobj.EnableSsl = false;
            obj = new System.Net.Mail.MailMessage();
            obj.From = new MailAddress("anilmeets4u@gmail.com", "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 it will work fine


Regards,

Anilkumar.D


引用此链接:

邮件发送问题 [
Refer this link:

Problem in Mail Sending[^]


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆