我想上传图像到数据库,并在用户单击保存按钮时发送电子邮件。当用户点击保存时数据库上传工作正常,但电子邮件没有正确发送。如何在c#窗体中的邮件图像框中添加图像
我是否正确格式化了msg.body
?
try
{
u.Open();
SqlCommand i = new SqlCommand("insert into BMS values('" + p + "')", u);
i.ExecuteNonQuery();
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("[email protected]", "*****");
Msg.To.Add("[email protected]");
string _fname = pictureBox1.ToString();
Msg.Attachments.Add(new Attachment(_fname));
Msg.Subject = "user credential sent from bank ";
Msg.Body = "<img [email protected]'+ pictureBox.Image + />";
Msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "****");
smtp.EnableSsl = true;
smtp.Send(Msg);
MessageBox.Show("Data inserted successfully and data's mailed ");
u.Close();
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
除此之外,似乎并不像是发送实际图像部分的方式..当您尝试发送它时会发生什么?它运行哪些代码行?编号预计你会得到一个单行文字说图像或其中的东西的邮件 – BugFinder
我认为,在msg.body中的代码是错误的 - 可以写什么代码? – gokul
实际上图像正在保存在数据库中,但邮件部分不工作,我喜欢发送该图像形式邮件编号作为附件当保存点击 – gokul