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 Trapp
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.
– Mariana
On which line of code the program hangs?
– Oralista de Sistemas
It does not report, it keeps loading, loading and does not send. Without the attachment, in a matter of seconds send.
– Mariana
Look at the error you are accusing: [Violation] 'setTimeout' Handler Took 100ms
– Mariana
You can find the line on which the system will debug it (put breakpoints in the code and press F5 in Visual Studio).
– Oralista de Sistemas