0

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!

Edited by __avd: Added [code] tags.

5
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by jugosoft
0

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

0

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();
    }
}

Edited by umamahesh2020: n/a

0

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 
        {
 
        }
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.