public int SendMessage(string subject, string messageBody, string fromAddress, string toAddress){ MailMessage message = new MailMessage(); message.IsBodyHtml = true; SmtpClient client = new SmtpClient(); message.From = new MailAddress(fromAddress.ToString()); if (toAddress.Trim().Length > 0) { foreach (string addr in toAddress.Split(';'))//you can use any delimiter { message.To.Add(new MailAddress(addr)); } } Attachment attachFile = new Attachment("D:\\a.xls");//you can also get the file name with using fileupload control message.Attachments.Add(attachFile); message.Subject = subject; message.Body = messageBody; client.Host = "smtp address"; client.Port = 587;//put your smtp port number client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential("mail id", "password"); client.Send(message); return 1;}
Public Function SendMessage(ByVal subject As String, ByVal messageBody As String, ByVal fromAddress As String, ByVal toAddress As String) As Integer Dim message As MailMessage = New MailMessage() message.IsBodyHtml = True Dim client As SmtpClient = New SmtpClient() message.From = New MailAddress(fromAddress.ToString()) message.To.Add(New MailAddress(toAddress.ToString())) Dim attachFile As Attachment = New Attachment("D:\\a.xls") 'specify your file location message.Attachments.Add(attachFile) message.Subject = subject message.Body = messageBody client.Host = "smtp address" ' put your smtp address client.Port = 587 ' put your port number for smtp client.UseDefaultCredentials = True client.Credentials = New System.Net.NetworkCredential("smtp login mail id", "smtp login password") client.Send(message) Return 1End Function