Delay Sending Email with Attachment

5

I'm trying to send an email with an attachment, without an attachment, the email sends quickly, without any problems, but when I put the attachment, it takes a lot of minutes, and it hangs, and it does not send.

I wonder if there is some way I can send it fast, or if it is my code that is poorly structured. Remember that I use tinyMCE for HTML settings. I believe that it does not have problem, since it sends normally without annex.

Follow how 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);
    
asked by anonymous 13.07.2017 / 13:26

1 answer

3

I do not understand why this happens only when an 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 started by".

    
13.07.2017 / 20:31