asp.net c#脚本中的mail senidng [英] mail senidng in asp.net c# script

查看:61
本文介绍了asp.net c#脚本中的mail senidng的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



忘记我发送的所有信息(在asp.net中发送邮件的错误).和

请在asp.net c#script中提供正确的发送邮件的完整代码.

请帮助我.

Hi,

Forget all I send (error of sending mail in asp.net). and

Please give the correct full code of sending mail in asp.net c#script.

Please help me.

推荐答案

添加此命名空间
使用System.Web.Mail;

下面的代码在按钮中

add this name space
using System.Web.Mail;

this code below in button

MailMessage mail = new MailMessage();
mail.To = "mail_id";
//for example
mail.To = "info@twinkle.in";


mail.From = "Twinkle"; // or text box value
mail.Subject = "for a query";// or text box value
mail.Body = "First Name: " + TextBox1.Text + "\n Last Name: " +  TextBox2.Text;
SmtpMail.SmtpServer = "your server";

try
        {
            SmtpMail.Send(mail);
mail send succesffully
        }
        catch
        {

mail send not  succesffully
        }


protected void btnSendmail_Click(object sender, EventArgs e)
 {
   // System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
   // System.Net.Mail.SmtpClient is the alternate class for this in 2.0
   SmtpClient smtpClient = new SmtpClient();
   MailMessage message = new MailMessage();

   try
   {
       MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text);

       // You can specify the host name or ipaddress of your server
       // Default in IIS will be localhost
       smtpClient.Host = "localhost";

       //Default port will be 25
       smtpClient.Port = 25;

       //From address will be given as a MailAddress Object
       message.From = fromAddress;

       // To address collection of MailAddress
       message.To.Add("admin1@yoursite.com");
       message.Subject = "Feedback";

       // CC and BCC optional
       // MailAddressCollection class is used to send the email to various users
       // You can specify Address as new MailAddress("admin1@yoursite.com")
       message.CC.Add("admin1@yoursite.com");
       message.CC.Add("admin2@yoursite.com");

       // You can specify Address directly as string
       message.Bcc.Add(new MailAddress("admin3@yoursite.com"));
       message.Bcc.Add(new MailAddress("admin4@yoursite.com"));

       //Body can be Html or text format
       //Specify true if it  is html message
       message.IsBodyHtml = false;

       // Message body content
       message.Body = txtMessage.Text;

       // Send SMTP mail
       smtpClient.Send(message);

       lblStatus.Text = "Email successfully sent.";
   }
   catch (Exception ex)
   {
       lblStatus.Text = "Send Email Failed." + ex.Message;
   }
 }


我确实为您提供了指向Microsoft文章的链接,该文章对所有内容进行了解释.看来您删除了该问题:doh:

现在,在这里,您可以看一下此Microsoft Video教程:
使用ASP.NET发送来自网站的电子邮件 [
I did gave you a link to Microsoft article that explains all. Looks like you deleted that question :doh:

Now, here you go, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]


这篇关于asp.net c#脚本中的mail senidng的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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