[2008] SMTP MailMessage Freezes My PC
Hi,
I'm using the below code to send mail with attachment, its working fine except that my PC freezes for 10 seconds whenever I run this code, is there a way to avoid system lag?,
I tried to lower the process priority by using "Process.GetCurrentProcess.PriorityClass = ProcessPriorityClass.Idle" but it didn't help.
Any suggestions please?
Code:
Dim MyMailMessage As New MailMessage
Try
MyMailMessage.From = New MailAddress("[email protected]")
MyMailMessage.To.Add("[email protected]")
MyMailMessage.Subject = "Mail Subject...."
Dim attch As New Mail.Attachment("C:\Picture.jpeg")
MyMailMessage.Attachments.Add(attch)
MyMailMessage.Body = "Message text...."
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.Port = 587
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("[email protected]", "myemailpassword")
SMTP.Send(MyMailMessage)
Catch ex As Exception
End Try
Re: [2008] SMTP MailMessage Freezes My PC
Hmmmnnn... Probably using a Backgroundworker to do the sending?
Re: [2008] SMTP MailMessage Freezes My PC
Are you saying that your whole system becomes unresponsive for 10 seconds or just your application? What happens if you send the same e-mail from your default e-mail client?
Re: [2008] SMTP MailMessage Freezes My PC
My whole system freezes when using the above code, I tried sending the same email via outlook and it went through without problems!
Re: [2008] SMTP MailMessage Freezes My PC
Is Outlook set up to use port 587 for SMTP as well?
Maybe it is set to use port number 25 which is the default.
Set the port to 25 in your code and see if it works.
Re: [2008] SMTP MailMessage Freezes My PC
Hey,
How big is the attachment that you are trying to add to the email?
You might want to look into the SmtpClients SendAsync method.
http://msdn.microsoft.com/en-us/library/x5x13z6h.aspx
You might have some luck with this.
Hope this helps.
Gary
Re: [2008] SMTP MailMessage Freezes My PC
Use SMTPClient.SendAsync for a non-blocking operation.