Wysylanie maila z załacznikami

0

Witam,

Mam problem z wysyłaniem maila na okreslony adres pocztowy.
Procedura SENDMAIL <ort>wyżuca </ort>mi taki wyjatek:

 at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, Strin
g response)
   at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, Stri
ng from)
   at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressColl
ection recipients, String deliveryNotify, SmtpFailedRecipientException& exceptio
n)
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at MailSender.SendMail.SENDMAIL() in C:\Documents and Settings\Pawel\Moje dok
umenty\Visual Studio 2005\Projects\MailSender\MailSender\Class1.cs:line 131
   at MailSender.SendMail.sendMail() in C:\Documents and Settings\Pawel\Moje dok
umenty\Visual Studio 2005\Projects\MailSender\MailSender\Class1.cs:line 97
   at SendingMails.Program.Main(String[] args) in C:\Documents and Settings\Pawe
l\Moje dokumenty\Visual Studio 2005\Projects\SendingMails\SendingMails\Program.c
s:line 23
private void SENDMAIL()
        {
            
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(this.from);//tutaj jest  [email protected]
            msg.To.Add(new MailAddress(this.to));// [email protected]
            
            foreach( String recAdres in this.rec_adresses)
               msg.To.Add(new MailAddress(recAdres)); //dodatkowi odbiorcy

            msg.Subject = this.subject;
            msg.Body = this.body;
            msg.IsBodyHtml = false;

            msg.BodyEncoding = System.Text.Encoding.GetEncoding("iso-8859-2");

            foreach(String fpath in this.attatchment_patch)
            {
              Attachment ma = new Attachment(fpath); //sciezki do zalacznikow
              msg.Attachments.Add(ma);
            }

            
            SmtpClient client = new SmtpClient();
            client.Credentials = CredentialCache.DefaultNetworkCredentials;
            client.Host = this.SmtpAdress;// tutaj jest smtp.wp.pl
            
            client.Send(msg);
            
            //client.SendAsync(msg, userState); //to też nie działa
         }

Z góry dziekuję za pomoc
Paweł

0

Pozwolę się podpiąć pod ten temat. Chcę wysłać maila za pomocą tlen.pl. Mimo, że uwierzytelnianie mam na true ciągle wyrzuca mi, że połączenie wymaga uwierzytelniania. :-/ Zaś gdy zmienie port na 465 i chcę wysłać maila za pomocą interia.pl upływa czas operacji.....
Co robię źle?

            MailMessage wiadomosc = new MailMessage(Od, Do);
            wiadomosc.Subject = txtTemat.Text;
            wiadomosc.Body = txtWiadomosc.Text;
            if (CC != null)
                wiadomosc.CC.Add(CC);

            try
            {
                klient = new SmtpClient(txtSerwer.Text);
                if (txtLogin.Text != String.Empty && txtHaslo.Text != String.Empty)
                {
                    klient.Credentials = new NetworkCredential(txtLogin.Text, txtHaslo.Text);
                }
                klient.Port = 25;
                klient.UseDefaultCredentials = true;
                klient.Send(wiadomosc);
                Status("Wiadomość została wysłana");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Brak połaczenia z serverem: " + ex.ToString());
            }
0

klient.UseDefaultCredentials = true;

zmian na false

0

tak samo..

0

@autor: jaka jest tresc bledu? Podaj szczegoly wyjatku.

0
System.Net.Mail.SmtpException was unhandled
  Message="Transaction failed. The server response was: 5.7.1 <[email protected]>: Sender address rejected: SERWER poczta.o2.pl WYMAGA UWIERZYTELNIENIA. Zobacz http://pomoc.o2.pl/poczta/autoryzacja/ i skonfiguruj poprawnie program pocztowy."
  Source="System"
  StackTrace:
       at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
       at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
       at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at Email.Form1.btnWyslij_Click(Object sender, EventArgs e) in E:\Moje dokumenty\Visual Studio 2005\Sieć\Email\Email\Form1.cs:line 66
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Email.Program.Main() in E:\Moje dokumenty\Visual Studio 2005\Sieć\Email\Email\Program.cs:line 17
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
0

@kurtth: nie jestes autorem posta ;)

A co do Twojego problemu to UseDefaultCredentials na false i sprobuj podac w konstruktorze NetworkCredentials jeszcze domene, z ktorej wysylasz maila. Zakladam, ze if przechodzi?

0

Witam

pozwole sobie zauwazyc ze mam ten sam problem i szukam w sieci odpowiedzi ale zadne przyklad nie dziala :( Madre ziomki mozecie zernkac na kod i wypowiedziec sie co jest nie tak ?

zastanawia mnie to ze nawet przyklady z helpa z MSDN nie chca dzialac
to sie jakos kupy nie trzyma
pozdrawiam
Seba

a to sa przyklady testowane przez mnie :


wiadomosc wysylana do siebie

      MailMessage wiadomosc = new MailMessage("[email protected]", "[email protected]");
        wiadomosc.Subject = "subj";
        wiadomosc.Body = "tresc";

        SmtpClient klient;
        try
        {
            klient = new SmtpClient("smtp.wp.pl");
            klient.
            klient.Credentials = new NetworkCredential("login", "haslo");
            klient.Port = 465;//lub 25 tez d..a
            klient.UseDefaultCredentials = false;
            klient.Send(wiadomosc);
            MessageBox.Show("Wiadomość została wysłana");
        }
        catch (Exception ex)
        {
            MessageBox.Show("Brak połaczenia z serverem: " + ex.ToString());
        }
        // Command line argument must the the SMTP host.
       
        -----------------------------------------------------------------------------------
        SmtpClient client = new SmtpClient("smtp.wp.pl");
        // Specify the e-mail sender.
        // Create a mailing address that includes a UTF8 character
        // in the display name.
        MailAddress from = new MailAddress("[email protected]","Jane " + (char)0xD8 + " Clayton",System.Text.Encoding.UTF8);
        // Set destinations for the e-mail message.
        MailAddress to = new MailAddress("[email protected]");
        // Specify the message content.
        MailMessage message = new MailMessage(from, to);
        message.Body = "This is a test e-mail message sent by an application. ";
        // Include some non-ASCII characters in body and subject.
        string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
        message.Body += Environment.NewLine + someArrows;
        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.Subject = "test message 1" + someArrows;
        message.SubjectEncoding = System.Text.Encoding.UTF8;
        // Set the method that is called back when the send operation ends.
        client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
        // The userState can be any object that allows your callback 
        // method to identify this send operation.
        // For this example, the userToken is a string constant.
        string userState = "test message1";
        client.SendAsync(message, userState);
        Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
        string answer = Console.ReadLine();
        // If the user canceled the send, and mail hasn't been sent yet,
        // then cancel the pending operation.
        if (answer.StartsWith("c") && mailSent == false)
        {
            client.SendAsyncCancel();
        }
        // Clean up.
        message.Dispose();
        Console.WriteLine("Goodbye.");

        MailAddress to = new MailAddress("[email protected]");
        MailAddress from = new MailAddress("[email protected]");
        MailMessage message = new MailMessage(from, to);
        message.Subject = "Using the new SMTP client.";
        message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
        // Use the application or machine configuration to get the 
        // host, port, and credentials.
        SmtpClient client = new SmtpClient("smtp.wp.pl",465);
        Console.WriteLine("Sending an e-mail message to {0} at {1} by using the SMTP host {2}.",to.User, to.Host, client.Host);
        client.EnableSsl = true;
        client.Credentials = new NetworkCredential("login", "haslo", "smtp.wp.pl");
        try
        {
            client.Send(message);
        }
        catch
        {
            MessageBox.Show("error");
        }
0

o2.pl i wp.pl z tego co mi wiadomo używają sposobu autentyfikacji nieobsługiwanego w .Net <ort>pÓÓÓÓki </ort>co. Ale nic nie stoi na przeszkodzie by zastosować jakieś opensourcowe biblioteki do protokołu SMTP, których jest pełno w sieci. Nawet tych napisanych w C#.

0

włącz ssl i zadziała

1 użytkowników online, w tym zalogowanych: 0, gości: 1