I have used mailing in asp on local host which worked fine but The prob has occurred when i hosted the pages the error message is: Failure sending mail.


and the code i am using:

Dim message As New MailMessage
                  message.From = New MailAddress("xxx@gmail.com")
                  message.To.Add(New MailAddress("xxx@yahoo.com"))
                  message.Subject = test mail""
                  message.Body = "Hi you have got a test mail from me!



                  Dim client As New SmtpClient
                  client.Credentials = New System.Net.NetworkCredential("xxx@gmail.com", "xxxxxxx")
                  client.Port = 587
                  client.Host = "smtp.gmail.com"
                  client.EnableSsl = True
                  client.Send(message)

Please help me!

to get exact error, put it in a try, catch (errmsg is a label on the form)
Try
Client.Send(message)


Catch smtpEx As SmtpException
'A problem occurred when sending the email message
errmsg.text = "Problem sending message: " & smtpEx.Message.Replace("'", "\'")


Catch generalEx As Exception
'Some other problem occurred
errmsg.text = "Sending Mail Failed. General Exception! " & generalEx.Message.Replace("'", "\'")

End Try

do you finish your iis configuration at your system.

Try This Code

using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Windows.Forms;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {

            MailMessage mm = new MailMessage();
            SmtpClient smtp = new SmtpClient();
            mm.From = new MailAddress(txtFrom.Text);
            mm.To.Add(new MailAddress(txtTo.Text));
            //mm.To.Add(new MailAddress(umamahesh2020@gmail.com));
            mm.Subject = txtSubject.Text;
            mm.Body = txtMessage.Text;
            mm.IsBodyHtml = true;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
            NetworkCred.UserName = "xxxx@gmail.com";
            NetworkCred.Password = "xxxx";
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = NetworkCred;
            smtp.Port = 587;//this is Gmail port for e-mail
            smtp.Send(mm);//send an e-mail 

            MessageBox.Show("Message Sended");
        }
        catch 
        {
        
        }
    }
    protected void btnCancle_Click(object sender, EventArgs e)
    {
        txtFrom.Text = txtMessage.Text = txtTo.Text = txtSubject.Text = "";
        txtTo.Focus();
    }
}

You use default creditians, and you specified to use your creditians. That could be why the error is generated. Change following section of your code to:

protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {
 
            MailMessage mm = new MailMessage();
            SmtpClient smtp = new SmtpClient();
            mm.From = new MailAddress(txtFrom.Text);
            mm.To.Add(new MailAddress(txtTo.Text));
            //mm.To.Add(new MailAddress(umamahesh2020@gmail.com));
            mm.Subject = txtSubject.Text;
            mm.Body = txtMessage.Text;
            mm.IsBodyHtml = true;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
            NetworkCred.UserName = "xxxx@gmail.com";
            NetworkCred.Password = "xxxx";
            smtp.UseDefaultCredentials = false; // I changed this value to false
            smtp.Credentials = NetworkCred;
            smtp.Port = 587;//this is Gmail port for e-mail
            smtp.Send(mm);//send an e-mail 
 
            MessageBox.Show("Message Sended");
        }
        catch 
        {
 
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.