private void btnSend_Click_1(object sender, EventArgs e)
        {

             To = txtPhoneNumber.Text.Trim() + cboCarrier.SelectedItem.ToString().Trim();
             From = txtSender.Text.Trim();
             Subject = txtSubject.Text.Trim();
             MailServer = txtMailServer.Text.Trim();
             Msg = txtMessage.Text.Trim();


             try
             {
                 MailMessage message = new MailMessage(From, To, Subject, Msg);
                 SmtpClient mySmtpClient = new SmtpClient(MailServer);
                 mySmtpClient.UseDefaultCredentials = true;
                 mySmtpClient.Send(message);
                 MessageBox.Show("Message has been sent to " + message.To.ToString(), "Mail", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }

It seems this is the event that is causing the issue , but I dont know why here is the exception I get from Windows when I click "send" :

http://i.imgur.com/ZBUhk.png

Recommended Answers

All 9 Replies

Do you have a mail server listening on port 25 of whatever machine 'MailServer' is?

no i havent even configured that and the MailServer is the machine im developing it on . But what exactly is the problem and why is that exception popping up? I thought sending a mail would not require credentials mainly because its being bounced on the server (in my knowledge)

To send mail it needs to connect to a mail server. You've told it that your machine is a mail server and to send the mail there. Since you have no mail service running, it can't connect to it and you get the error.

so is there code to signify to tell the program to bounce off another server(probably look online or should I still use smtp server from gmail or even a generic one) . Since the problem is the program does not have a mail server to send the message to?

Thanks

if I just find a free public smtp server will it do the trick because it could also be that my ISP is blocking connections to port 25 to other services unless it is its own smtp server.

It should, yes

 try
             {
                 MailMessage message = new MailMessage(mFrom, mTo, mSubject, mMsg);
                 SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 25);
                 System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("mail@gmail.com", "password");
                 //smtpClient.Send(message);
                // smtpClient.UseDefaultCredentials = false;
                 //smtpClient.Credentials = credentials;

                 SmtpClient mySmtpClient = new SmtpClient(mMailServer);
                 mySmtpClient.UseDefaultCredentials = false;
                 mySmtpClient.Send(message);
                 MessageBox.Show("Message has been sent to " + message.To.ToString(), "Mail", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }

This is what I have implemented so far . I have told the system to get auth and even where to refer to a smtp client and its port but again another issue arises http://i.imgur.com/rLTqI.png

Nevermind I solved it by finding out that you have to use your ISP's own smtp server

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.