Click here to Skip to main content
15,917,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

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

CSS
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.



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

VB
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
Posted

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[^]
 
Share this answer
 
look This[^]
and check that in your web.config file have you add these lines

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900