如何在ASP.net中发送电子邮件 [英] How to send email in ASP.net

查看:70
本文介绍了如何在ASP.net中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

如何在asp.net中发送电子邮件.我尝试下面的代码并在Internet上托管,但出现错误.

Dear All,

How to send the email in asp.net. I try the below code and host on internet i got the error.

The "SendUsing" configuration value is invalid.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The "SendUsing" configuration value is invalid.




我尝试3种类型的代码,但没有成功,代码如下.




I try 3 type of code but no success, the code is below.

Private Sub Frm_SendingEmail()
        'Dim MsgMail_ForgetPws As New MailMessage

        'With MsgMail_ForgetPws
        '    .From = "noreply@shaleem.net"
        '    .To = TextBox1.Text
        '    .Subject = "Test"
        '    .BodyFormat = MailFormat.Html
        '    '.Body = "Leave Number is :" & Space(1) & txtLeaveNo.Text & "and reason is :" & Space(1) & txtReason.Text
        '    .Body = "Test Email"

        'End With
        'SmtpMail.Send(MsgMail_ForgetPws)
        'MsgMail_ForgetPws = Nothing
        'Label2.Text = "Sent Successfully"

        Dim email

        email = Server.CreateObject("CDO.Message")
        email.Subject = "Sending email with CDO"
        email.From = "noreply@shaleem.net"
        email.To = TextBox1.Text
        email.HTMLBody = "Hi"
        email.Send()
        Response.Write("Mail Sent!")
        email = Nothing





    End Sub


    Public Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, ByVal subject As String, ByVal body As String)
        ' Instantiate a new instance of MailMessage
        Dim mMailMessage As New MailMessage()

        ' Set the sender address of the mail message
        mMailMessage.From = New MailAddress(from)
        ' Set the recepient address of the mail message
        mMailMessage.To.Add(New MailAddress(recepient))

        ' Check if the bcc value is nothing or an empty string
        If Not bcc Is Nothing And bcc <> String.Empty Then
            ' Set the Bcc address of the mail message
            mMailMessage.Bcc.Add(New MailAddress(bcc))
        End If

        ' Check if the cc value is nothing or an empty value
        If Not cc Is Nothing And cc <> String.Empty Then
            ' Set the CC address of the mail message
            mMailMessage.CC.Add(New MailAddress(cc))
        End If

        ' Set the subject of the mail message
        mMailMessage.Subject = subject
        ' Set the body of the mail message
        mMailMessage.Body = body

        ' Set the format of the mail message body as HTML
        mMailMessage.IsBodyHtml = True
        ' Set the priority of the mail message to normal
        mMailMessage.Priority = MailPriority.Normal

        ' Instantiate a new instance of SmtpClient
        Dim mSmtpClient As New SmtpClient()
        ' Send the mail message
        mSmtpClient.Send(mMailMessage)

    End Sub

推荐答案

请参阅一篇有关CP的好文章:
使用System.Web.Mail命名空间发送邮件 [ ^ ]

这是另一个好东西:
如何使用VB.NET代码发送电子邮件 [发送电子邮件 [
Please refer a good article on CP:
Send mail using System.Web.Mail namespace[^]

Here''s another good one:
How to send email using VB.NET code[^]

This one is give you code to send mails with attachments:
Sending Email[^]


外观
look This[^]
and check that in your web.config file have you add these lines

<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="PickupDirectoryFromIis"/>
    </mailSettings>
  </system.net>
  <system.web>
    <authentication mode="Forms" />
  </system.web>



尝试访问以下链接:
http://msdn.microsoft.com/en-us/library/system. net.mail.smtpclient.aspx [ ^ ]
http://msdn.microsoft.com/en-us/vstudio/bb630227.aspx [ ^ ]

祝一切顺利.
--AK
Hi,
Try visiting these links:
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx[^]
http://msdn.microsoft.com/en-us/vstudio/bb630227.aspx[^]

All the best.
--AK


这篇关于如何在ASP.net中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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