Sending mail with attachments programmatically in ASP.NET

    protected void btnSend_OnClick(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        byte[] data = new byte[1024];
        MemoryStream stream = new MemoryStream(data);
        Attachment attach = new Attachment(stream, "Attachment file name");
        mail.Attachments.Add(attach);
        new SmtpClient().Send(mail);
    }

You might be able to create System.Net.Mail.Attachment from string then send out the mail as normal.

var m = new System.Net.Mail.MailMessage(from, to, subject, body);
var a = System.Net.Mail.Attachment.CreateAttachmentFromString(stringWrite.ToString(), "application/vnd.xls");
m.Attachments.Add(a);