Sending Email

I tried a script using System.Net.Mail, and configuring some lines in the web.config.

Well what happened is that it only sends mail on the address you configured in the web.config. What I am trying to do is I want to send a copy to the client who send an inquiry.

One copy to me and One copy to the person who sends an inquiry.

Thanks

Show your code.

<mailSettings>
      <smtp>
        <network host="[I]HOSTNAME[/I]" port="[I]portnumber[/I]" userName="[I]username[/I]" password="[I]password[/I]"/>
        
      </smtp>
    </mailSettings>

This is from WEB.CONFIG

This is EmailAdmin.vb


Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Net.Mail
Imports Microsoft.VisualBasic

Public Class EmailAdmin
    Public Function SendMail(ByVal FromMail As String, ByVal EmailBody As String) As MailMessage
        Const ToAddress As String =  "myemail@hostfromwebconfig"
        Dim mm As New MailMessage(FromMail, ToAddress)
        mm.Subject = "INQUIRY FROM WEBSITE"
        mm.Body = EmailBody
        mm.IsBodyHtml = False
        Return mm
    End Function

    Public Function SendInquirer(ByVal Inq_Name As String, ByVal ToInquirer As String, ByVal Tick As String) As MailMessage
        Const AdminEmail As String = "myemail@hostfromwebconfig"
        Dim MailMessage As String = "WELCOME " & Inq_Name & "," & _
        "<p>Your Inquiry has been forwarded and will be reviewes</p>" & _
        "YOUR TICKET NUMBER : " & Tick & " " & _
        "Thank for sending an inquiry this will help us improve our service to you" & _
        "Regards," & _
        "Miletrix Trading Inc." & _
        "Please do not reply this is server generated email. Thank You"


        Dim inq_mail As New MailMessage(AdminEmail, ToInquirer)

        inq_mail.Subject = "THANKS FOR INQUIRING"
        inq_mail.Body = MailMessage
        inq_mail.IsBodyHtml = False

        Return inq_mail
    End Function


End Class

This will trigger the send

 Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
        Dim CLS_Connect As New WebConnection
        Dim CLS_MailAdmin As New EmailAdmin

        Dim DS_Connect As New DataSet
        Dim SendMail As New SmtpClient
        'Dim STR_INS_Insert As String

     
        If Page.IsValid Then
            valCaptcha.Visible = True
            valCaptcha.Text = "YOUR INQUIRY SUCCESSFULLY SUBMITTED"
            valCaptcha.ForeColor = Drawing.Color.Blue

            SendMail.Send(CLS_MailAdmin.SendMail(txtEmail.Text, txtInquiry.Text))
            SendMail.Send(CLS_MailAdmin.SendInquirer(txtName.Text, txtEmail.Text, GenerateTicket()))





            txtEmail.Text = ""
            txtInquiry.Text = ""
            txtName.Text = ""


        Else
            valCaptcha.Visible = True

            valCaptcha.Text = "INVALID CAPTCHA CODE"
            valCaptcha.ForeColor = Drawing.Color.Red

        End If
    End Sub

It practically sends to my email… see the config…
but not to the inquirer’s email

Thanks!

Slightly off-topic, but when I click the link in your signature, NOD32 gave me this warning:

What do you have going on over there?

Hmmm… but please be calm, I am no virus spreader or something. It is hosted in a free hosting and under co.cc domain.

but it should be…

Back to your question…are the smtp server settings in web.config correct? Incorrect settings can allow local mail to go through but fail when sending to another server.

Can you try a simple test with this code? Send it to an account that isn’t local on the server.

:slight_smile: I wasn’t implying that you were a bad guy! I’ve actually never run into a site that my AV blocked me out of before.

Those co.cc domains sure have a bad reputation! :eek:

It’s really quite an old domain… even google blocked the co.cc domains.
Hopefully will have a decent dot com sooner…

Thanks for understanding man.

THIS THREAD IS SOLVED!!! Will share the solution later after I test it more.

Thanks For The Reply!
FFCus see you 'round

great such effect the tools send the mail first you can add
system.net.mail
then web.config create the connection the and local host name and username and password name
then define the alias of the connection in the code then work your code manually send the mail

Well what was the solution? You said you would share it 2 months ago. Have you tested anything yet?

Im happy this morning until I saw this reply… Do I owe you something?


Imports System.Web
Imports System.Net.Mail
Imports System.Net.Mail.SmtpClient
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb


IMPORT EVERYTHING.

Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
        Dim CLS_MailAdmin As New EmailAdmin
        Dim SendMail As New SmtpClient
        Dim strGENTick As String
        'Dim STR_INS_Insert As String



        If Page.IsValid Then
            valCaptcha.Visible = True
            valCaptcha.Text = "YOUR INQUIRY SUCCESSFULLY SUBMITTED"
            valCaptcha.ForeColor = Drawing.Color.Blue
            strGENTick = GenerateTicket()
            CLS_MailAdmin.SaveInquiry(strGENTick, txtName.Text, txtEmail.Text, txtInquiry.Text, Now)

            Dim SmtpClient As New SmtpClient("[I][B]ip address[/B][/I]")
            SmtpClient.Credentials = New Net.NetworkCredential("username", "password")
            SmtpClient.Send(CLS_MailAdmin.SendInquirer(txtName.Text, txtEmail.Text, strGENTick))

            


            txtEmail.Text = ""
            txtInquiry.Text = ""
            txtName.Text = ""


        Else
            valCaptcha.Visible = True

            valCaptcha.Text = "INVALID CAPTCHA CODE"
            valCaptcha.ForeColor = Drawing.Color.Red

        End If
    End Sub

This where you hit send.

 Public Function SendInquirer(ByVal Inq_Name As String, ByVal ToInquirer As String, ByVal Tick As String) As MailMessage

        Dim MailMessage As String = "<p>WELCOME " & Inq_Name & ",</p>" & _
        "<p>Your Inquiry has been forwarded and will be reviewed</p>" & _
        "<br /><br />" & _
        "<p>YOUR TICKET NUMBER : " & Tick & "</p> " & _
        "<br /><br />" & _
        "<p>Thank you for sending an inquiry this will help us improve our service to you </p>" & _
        "<br />" & _
        "<p>Regards,</p>" & _
        "<p>COMPANY NAME</p>" & _
        "<em>Please do not reply this is server generated email. Thank You </em>"

        Dim inq_mail As New MailMessage("email admin", ToInquirer)

        inq_mail.Subject = "THANKS FOR INQUIRING"
        inq_mail.Body = MailMessage
        inq_mail.IsBodyHtml = True

        Return inq_mail
    End Function

THEN THE MESSAGE

Experiment more… Thanks for the replies of nice people before the reply of the above.