Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: S1dD3xt35 en 13 Marzo 2011, 00:37 am



Título: Problema con programa para enviar correos
Publicado por: S1dD3xt35 en 13 Marzo 2011, 00:37 am
saludos a todos, bueno tengo un problema con un codigo que estoy haciendo para enviar correos con archivo abjunto, cuando adjunto el achivo y lleno todos los datos me marca error en esa parte.

bueno espero alguien me pueda ayudar saludos.



Código
  1. cliente.Send(msg);  

codigo completo

Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Net.Mail;
  10. using System.Net;//librerias
  11. using System.Web;//librerias
  12.  
  13. namespace correo
  14. {
  15.    public partial class Form1 : Form
  16.    {
  17.  
  18.  
  19.        public Form1()
  20.        {
  21.            InitializeComponent();
  22.        }
  23.  
  24.        SmtpClient cliente; //cliente de correo
  25.        MailMessage msg; //datos del correo
  26.        Attachment anexo; //anexos
  27.  
  28.  
  29.        private void button3_Click(object sender, EventArgs e)
  30.        {
  31.            cliente = new SmtpClient();
  32.            msg = new MailMessage();
  33.  
  34.            anexo = new Attachment(lblArchivoadjunto.Text);
  35.  
  36.  
  37.            //datos del correo
  38.            msg.Attachments.Add(anexo);
  39.            msg.Body = rbtTexto.Text;
  40.            msg.From = new MailAddress(txtcorreo.Text);
  41.            msg.Subject = asuntotxt.Text;
  42.            msg.To.Add(txtDestinario.Text);
  43.  
  44.            //credenciales
  45.            cliente.Credentials = new NetworkCredential(txtcorreo.Text,txtPass.Text);
  46.            cliente.Port = 25;
  47.            cliente.Host = comboBox1.Text;
  48.            cliente.EnableSsl = true;
  49.  
  50.            cliente.Send(msg);
  51.  
  52.  
  53.  
  54.  
  55.        }
  56.  
  57.        private void adjuntar_Click(object sender, EventArgs e)
  58.        {
  59.            OpenFileDialog open = new OpenFileDialog();
  60.  
  61.            if (open.ShowDialog() == DialogResult.OK) { lblArchivoadjunto.Text = open.FileName; };
  62.        }
  63.  
  64.  
  65.  
  66.    }
  67. }
  68.  


          


Título: Re: Problema con programa para enviar correos
Publicado por: [D4N93R] en 13 Marzo 2011, 15:27 pm
Si puedes poner el error y más detalles.

De todos modos checka el tamaño del archivo.

Un saludo.