CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Posts
    63

    [RESOLVED] can't send email

    Hello,

    I've got an application in which I'm trying to send email and it won't let me for some reason. Here is my code:

    Code:
                try
                {
                    MailMessage message = new MailMessage(sentFrom, sendTo, subject, body);
                    SmtpClient client = new SmtpClient(smtpServer);
                    client.Send(message);
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
    The problem is that this code works on my local machine when I use my smtp server but when I put it on someone else's machine, it doesn't work. I get various error messages depending on smptServer and on the delivery method.

    For example, if I have no delivery method, and I run this on my local machine but using the other person's smtp server, then I get the message:

    "Service not available, closing transmission channel. The server response was: 4.3.2 Service not available, closing transmission channel"

    If I include the line client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis right before I send, I get:

    "Cannot get IIS pickup directory."

    If I replace that line with SmtpDeliveryMethod.SpecifiedPickupDirectory, I get:

    "Only absolute directories are allowed for pickup directory."

    If I replace that line with SmtpDeliveryMethod.Network, I get the "service not available" message again.

    This is all if I run it on my local machine using the other person's smtp server. I haven't been able to test it on their machine with anything other than my own smtp server, but I know that none of the delivery methods work on their machine either. I have yet to try it on their machine with their smtp server with or without delivery methods (this will have to wait until they get back after the weekend).

    Can anyone see the problem? Do you think it's just a matter of using their smtp server on their machine (without a delivery method)?

  2. #2
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Talking Re: can't send email

    Try the following way .it is efficient way .and i have been using in so many big project .
    Code:
    private void SendMail(string attachmentFile) {
                try{
                    string BodyMessage = richTextBox1.Text;
                    MailMessage Message = new MailMessage();
                    Message.Bcc .Add("xyz@gmail.com");                
                    Message.Subject = ElectronicEmail.EmailSubject;
                    Message.From = new MailAddress("firoz.raj@gmail.com");
                    Message.Body = (BodyMessage); 
                    SmtpClient smtp = new SmtpClient("mail.alhokair.com.sa");
                    Attachment Attach = new Attachment(attachmentFile);
                    Message.Attachments.Add(Attach);
                    smtp.Send(Message);
                             }
                catch (Exception ex){
                    MessageBox.Show(ex.Message);
                    /* Logfile.CreateLog(Application.StartupPath.ToString(), ex.ToString()); */
                }
            }

  3. #3
    Join Date
    Nov 2011
    Posts
    63

    Re: can't send email

    The SMTP server name only works on a computer within the network that contains that SMTP server. That was the problem.

    Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured