I am trying to send a mail using Web.Mail in vb.net. It is working fine but when I try to attach the file using Upload File Control of asp.net, event is not getting fired on which the function is getting called to send mail..
sending the code too. Please help me out.
Public Sub SendMail(ByVal _To As String, ByVal _cc As String, ByVal _Bcc As String, _ ByVal Name As String) Try Dim _Path As String = "E:\Websites\Sales_Production\DefaultDir\Attachment" Dim msg As String = "" Dim oAttach As MailAttachment Dim objMail As New MailMessage() '_Path = Path.GetFullPath(UploadFile.PostedFile.FileName) Try oAttach = New MailAttachment(_Path) Catch ex As Exception End Try With objMail .To = _To '"email@example.com" .Cc = "firstname.lastname@example.org" '_cc .Bcc = _Bcc .From = "email@example.com" .Subject = "No Reply: SR mail from CRM-Web." .Body = txtBody.Text .BodyFormat = MailFormat.Html .Attachments.Add(oAttach) End With Try oAttach = New MailAttachment(_Path) objMail.Attachments.Add(oAttach) Catch ex As Exception lblBCC.Text = ex.Message End Try SmtpMail.SmtpServer = "192.168.1.4" SmtpMail.Send(objMail) Catch ex As Exception Msg = ex.Message MsgBox(Msg) End Try End Sub
Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks)