Demora ao Enviar Email com Anexo

Asked

Viewed 363 times

6

I am trying to send an email with attachment, without attachment, the email sends quickly, without any kind of problem, but when I place the attachment, it takes a lot, matter of minutes, and hangs, and does not send.

I wonder if there’s any way I can send it fast, or if it’s my code that’s poorly structured. Remembering that I use tinymce for HTML settings. I think it’s okay, since it sends normally without attachment.

Keep going like I’m doing. Here is the class:

public Attachment anexo;

email.IsBodyHtml = true;
email.From = new MailAddress(emailAdm);
foreach (var address in destinatario.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
{
    if (EmailValido(address))
    {
        email.Bcc.Add(address);
    }
    else { }
}
email.Subject = assunto;
email.Body = mensagem;
email.SubjectEncoding = System.Text.Encoding.UTF8;
if (anexo != null)
{
    email.Attachments.Add(anexo);
}

And here is the form code:

clsEnviarEmail email = new clsEnviarEmail();
email.destinatario = destinatario;
email.assunto = txtassunto.Text;
email.mensagem = txtMensagem.InnerText;
if (Anexo.HasFile)
{
    MemoryStream ms = new MemoryStream(Anexo.FileBytes);
    Attachment anexo = new Attachment(ms, Anexo.PostedFile.FileName);
    email.anexo = anexo;
}
email.Email();
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('E-mails enviado com sucesso!');", true);
  • What is the size of the annex?

  • Artur has tried all sizes, I am trying a txt file of 90KB and does not send. I have tried bigger and smaller, and the same problem happens.

  • On which line of code the program hangs?

  • It does not report, it keeps loading, loading and does not send. Without the attachment, in a matter of seconds send.

  • Look at the error you are accusing: [Violation] 'setTimeout' Handler Took 100ms

  • You can find the line on which the system will debug it (put breakpoints in the code and press F5 in Visual Studio).

Show 1 more comment

1 answer

2


I don’t understand why this happens only when some attachment is included in the email. However, I was able to resolve with proxy by placing the site address in advanced proxy options in "Do not use proxy server for addresses initiated by".

  • Your problem is below so not code.

  • I do not know for sure Renan, I just found it very strange this occur when it has attachment, when it has no attachment, no problem occurs.

  • 1

    Look, your network administrator put in an unrealistic timeout to access a resource through the proxy. 100 milliseconds can’t even blink. Uploading the attachment to the server, for less, takes more than that. Hence the problem.

  • I changed the timeout setting while sending the email, to maximum, but still not sent in proxy.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.