private void TsUp_Click(object sender, RoutedEventArgs e)
{
RenderTargetBitmap bmp = new RenderTargetBitmap(
(int)captureElement.ActualWidth, (int)captureElement.ActualHeight,
80, 80, PixelFormats.Default);
bmp.Render(captureElement);
BitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
using (MemoryStream ms = new MemoryStream())
{
encoder.Save(ms);
byte[] CaptureData = ms.ToArray();
File.WriteAllBytes("d:/1.jpg", CaptureData);
OpenFileDialog oFDialogSFile = new OpenFileDialog();
oFDialogSFile.InitialDirectory = ":\\";//设置对话框的初始目录为C盘
oFDialogSFile.Filter = "1.jpg|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";
oFDialogSFile.RestoreDirectory = true;
cboxAccessories.Items.Add(oFDialogSFile.FileName.Trim());
try
{
string file = "D:/1.jpg";
//SmtpClient下的一个对象,用以设置邮件的主题和内容
System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
//发送端到接收端的邮箱地址
myMail = new System.Net.Mail.MailMessage("发件人@qq.com", "收件人@qq.com");
myMail.Subject = "1";
myMail.Body = "123";
if (cboxAccessories.Items.Count > 0)
{
for (int i = 0; i < cboxAccessories.Items.Count; i++)
{ //建立邮件附件类的一个对象,语法格式为System.Net.Mail.Attachment(文件名,文件格式)
System.Net.Mail.Attachment myAttachment = new System.Net.Mail.Attachment(
cboxAccessories.Items[i].ToString(), System.Net.Mime.MediaTypeNames.Application.Octet);
//MIME协议下的一个对象,用以设置附件的创建时间,修改时间以及读取时间
System.Net.Mime.ContentDisposition disposition = myAttachment.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
//用smtpclient对象里attachments属性,添加上面设置好的myattachment
myMail.Attachments.Add(myAttachment);
}
}
//建立发送对象client,验证邮件服务器,服务器端口,用户名,以及密码
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.qq.com", Convert.ToInt32("25"));
client.Credentials = new System.Net.NetworkCredential("发件人号", "发件人密码");
client.Send(myMail);
}
catch (Exception ex)
{
MessageBox.Show("无法发送");
}
}
}
}
现在拍照保存功能已经可以实现,,就是发送邮件发送不了,多次测试也没找到原因。。
{
RenderTargetBitmap bmp = new RenderTargetBitmap(
(int)captureElement.ActualWidth, (int)captureElement.ActualHeight,
80, 80, PixelFormats.Default);
bmp.Render(captureElement);
BitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
using (MemoryStream ms = new MemoryStream())
{
encoder.Save(ms);
byte[] CaptureData = ms.ToArray();
File.WriteAllBytes("d:/1.jpg", CaptureData);
OpenFileDialog oFDialogSFile = new OpenFileDialog();
oFDialogSFile.InitialDirectory = ":\\";//设置对话框的初始目录为C盘
oFDialogSFile.Filter = "1.jpg|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";
oFDialogSFile.RestoreDirectory = true;
cboxAccessories.Items.Add(oFDialogSFile.FileName.Trim());
try
{
string file = "D:/1.jpg";
//SmtpClient下的一个对象,用以设置邮件的主题和内容
System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
//发送端到接收端的邮箱地址
myMail = new System.Net.Mail.MailMessage("发件人@qq.com", "收件人@qq.com");
myMail.Subject = "1";
myMail.Body = "123";
if (cboxAccessories.Items.Count > 0)
{
for (int i = 0; i < cboxAccessories.Items.Count; i++)
{ //建立邮件附件类的一个对象,语法格式为System.Net.Mail.Attachment(文件名,文件格式)
System.Net.Mail.Attachment myAttachment = new System.Net.Mail.Attachment(
cboxAccessories.Items[i].ToString(), System.Net.Mime.MediaTypeNames.Application.Octet);
//MIME协议下的一个对象,用以设置附件的创建时间,修改时间以及读取时间
System.Net.Mime.ContentDisposition disposition = myAttachment.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
//用smtpclient对象里attachments属性,添加上面设置好的myattachment
myMail.Attachments.Add(myAttachment);
}
}
//建立发送对象client,验证邮件服务器,服务器端口,用户名,以及密码
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.qq.com", Convert.ToInt32("25"));
client.Credentials = new System.Net.NetworkCredential("发件人号", "发件人密码");
client.Send(myMail);
}
catch (Exception ex)
{
MessageBox.Show("无法发送");
}
}
}
}
现在拍照保存功能已经可以实现,,就是发送邮件发送不了,多次测试也没找到原因。。