Sending Mail with Attachment in SharePoint 2010

                     string smtpServer = SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
                    string smtpFrom = SPAdministrationWebApplication.Local.OutboundMailSenderAddress;

                     string Email= "EmailID"
                     MailMessage mailMessage = new MailMessage(smtpFrom, Email);
                     mailMessage.Subject = txtSubject.Text;
                     mailMessage.Body = txtBody.Text;
                     WebClient webClient = new WebClient();
                     webClient.Credentials = CredentialCache.DefaultNetworkCredentials;
                     FileStream fs = new FileStream(pathToCheck, FileMode.Open, FileAccess.Read);
                     byte[] data = new byte[fs.Length];
                     fs.Read(data, 0, data.Length);
                     MemoryStream memoryStreamOfFile = new MemoryStream(data);
                     mailMessage.Attachments.Add(new                                   System.Net.Mail.Attachment(memoryStreamOfFile, filename));
                     SmtpClient smtpClient = new SmtpClient(smtpServer);
                     smtpClient.Send(mailMessage);

Comments

Popular posts from this blog

IRM and the Object Model

This content database has a schema version which is not supported in this farm

Activate and Deactivate Feature through PowerShell