0

テーブルを作成しました

create table files
(
id int identity(1,1),
Name_of_file varchar(50) null,
interviewfile varbinary(max) Null,
)

ファイル テーブルへの .doc ファイルの挿入

insert into files 
select 'DB Creation' as filetype, *
from openrowset
(BULK 'E:\Office Works\Get SMS\DBA SMS Exam Stuff with 
DocumentationStandards\Interview Questions\Indexes-I.doc', SINGLE_BLOB)
as x

「Indexes-I.doc」ファイルを特定のメール ID に添付して送信したいと考えています。

Asp.Net 3.5を使用して添付する方法と送信する方法

解決策を教えてください........

ありがとう、よろしく、 Venkat Kumar Chigulla。

4

2 に答える 2

0

少し変更する必要があるかもしれませんが、これで十分です。

private void SendEmail(string toAddress, string ccAddress, string bccAddress, string subject, string body, MailPriority priority, bool isHtml)
    {
        try
        {
            SmtpClient smtpClient = new SmtpClient();
            MailMessage message = new MailMessage();

            MailAddress fromAddress = new MailAddress("sample@hotmail.com");

            smtpClient.Host = "xxx.xxx.com";
            smtpClient.Port = 25;

            message.From = fromAddress;
            message.Priority = priority;
            message.To.Add(toAddress);
            message.Subject = subject;
            if (ccAddress.Length > 0)
            {
                message.CC.Add(ccAddress);
            }
            if (bccAddress.Length > 0)
            {
                message.Bcc.Add(bccAddress);
            }

            message.IsBodyHtml = isHtml;
            message.Body = body;

            //load attachment from database
            sConn = ConfigurationManager.ConnectionStrings["eCIConnectionString"].ToString();
            try
            {
                sSQL = @"SELECT id, Name_of_file,  interviewfile" +
                        @"FROM files " +
                        @"WHERE Name_of_file = 'Your FileName'";

                conn.ConnectionString = sConn;
                conn.Open();
                cmd.CommandText = sSQL;
                cmd.CommandType = CommandType.Text;
                cmd.Connection = conn;
                cmd.Parameters.Clear();

                dAdapter.SelectCommand = cmd;
                DataTable dt = new DataTable();
                dAdapter.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        byte[] barrImg = (byte[])dt.Rows[i]["interviewfile"];
                        string strfn = Convert.ToString(dt.Rows[i]["Name_of_file"]);
                        FileStream fs = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write);
                        fs.Write(barrImg, 0, barrImg.Length);

                        fs.Flush();
                        fs.Close();
                        fs.Dispose();

                        Attachment att = new Attachment(strfn);
                        message.Attachments.Add(att);
                    }
                }
            }
            catch (Exception ex)
            {
                string error = ex.Message + ex.StackTrace;
            }
            finally
            {
                if (conn != null)
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                    conn.Dispose();
                }
                if (cmd != null)
                {
                    cmd.Dispose();
                }
            }

            // Send SMTP mail
            smtpClient.Send(message);

            lblMessage.Text = "Email sent to " + toAddress + " successfully !";
        }
        catch (Exception ee)
        {
            lblMessage.Text = ee.ToString();
        }
    }

これがうまくいくことを願っています。

于 2013-08-29T10:25:01.047 に答える