6
Answers

How to send an email?

Photo of anjumathi kumar

anjumathi kumar

13y
3.4k
1
Hi i want to develop Email sending application....

i have tried coding like this


      public void sendMail(string toList, string fromlist, string ccList, string subject, string body)
        {
            MailMessage message = new MailMessage();
            SmtpClient smtpClient = new SmtpClient();
            MailAddress fromAddress = new MailAddress(fromlist);
            message.From = fromAddress;
            message.To.Add(toList);
            if (ccList != null && ccList != string.Empty)
            {
                message.CC.Add(ccList);
            }
            message.Subject = subject;
            message.IsBodyHtml = true;
            message.Body = body;
            smtpClient.Host = "127.0.0.1";
            smtpClient.Port = 25;
            smtpClient.UseDefaultCredentials = true;
            smtpClient.Credentials = new System.Net.NetworkCredential(txtfromadd.Text, txtpwd.Text);
            smtpClient.Send(message);

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //string fromadd = txtfromadd.Text;
            string tocc = "suguna@cavintek.com";
            sendMail(txtToAddress.Text, txtfromadd.Text, tocc, txtSubject.Text, txtContent.Text);
        }
but i got error in this line  smtpClient.Send(message);

iI want to change any settings in config...




Answers (6)

0
Photo of Jiteendra Sampathirao
NA 6.9k 1.5m 13y

Hi,
go through this thread


0
Photo of anjumathi kumar
NA 54 49.8k 13y
A socket operation was attempted to an unreachable network 127.0.0.1:25

i give correctly..i gave anju@yahoo.com ,****** like that oly credentials i gave i got sending mail failed
0
Photo of anjumathi kumar
NA 54 49.8k 13y
A socket operation was attempted to an unreachable network 127.0.0.1:25

i give correctly..i gave anju@yahoo.com ,****** like that oly credentials i gave i got sending mail failed

wat i want to change?
0
Photo of anjumathi kumar
NA 54 49.8k 13y
how can able to set up mailing server?
0
Photo of Suthish Nair
NA 31.7k 4.6m 13y
You need a valid Host to send mails.. First setup a mailing server or you can use free services provided by live.com or google.
0
Photo of Jiteendra Sampathirao
NA 6.9k 1.5m 13y

Hi,

what's the error you faced?

follow this article

hope it help you..