大家好有关邮件的问题
发表在C#图书答疑
2008-09-27
是否精华
是
否
版块置顶:
是
否
[font size=3]我在《C#数据库系统开发案例精选>>企业客户资源管理里面的邮件发送中遇到了发送失败的问题,我想请教大家,这是我添加按钮的代码:
[font size=2]try
{
string file = Application.StartupPath + "testXML.xml";
System.Net.Mail.MailMessage mymail = new MailMessage();
mymail = new System.Net.Mail.MailMessage(txtSEmail.Text.Trim(), txtCEmail.Text.Trim());
mymail.Subject = txtETitle.Text.Trim();
mymail.Body = txtEContent.Text.Trim();
if (cboxAccessories.Items.Count > 0)
{
for (int i = 0; i < cboxAccessories.Items.Count; i++)
{
System.Net.Mail.Attachment myattachment = new System.Net.Mail.Attachment(
cboxAccessories.Items[i].ToString(), System.Net.Mime.MediaTypeNames.Application.Octet);
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);
mymail.Attachments.Add(myattachment);
}
}
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(
txtSService.Text.Trim(), Convert.ToInt32(txtServicePort.Text.Trim()));
client.Credentials = new System.Net.NetworkCredential(txtUName.Text.Trim(), txtUPwd.Text.Trim());
client.Send(mymail);
MessageBox.Show("邮件发送成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}[/font][/font]
调式的时候全部过了 到 client.Send(mymail);这里就没有执行成功
[font size=2]try
{
string file = Application.StartupPath + "testXML.xml";
System.Net.Mail.MailMessage mymail = new MailMessage();
mymail = new System.Net.Mail.MailMessage(txtSEmail.Text.Trim(), txtCEmail.Text.Trim());
mymail.Subject = txtETitle.Text.Trim();
mymail.Body = txtEContent.Text.Trim();
if (cboxAccessories.Items.Count > 0)
{
for (int i = 0; i < cboxAccessories.Items.Count; i++)
{
System.Net.Mail.Attachment myattachment = new System.Net.Mail.Attachment(
cboxAccessories.Items[i].ToString(), System.Net.Mime.MediaTypeNames.Application.Octet);
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);
mymail.Attachments.Add(myattachment);
}
}
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(
txtSService.Text.Trim(), Convert.ToInt32(txtServicePort.Text.Trim()));
client.Credentials = new System.Net.NetworkCredential(txtUName.Text.Trim(), txtUPwd.Text.Trim());
client.Send(mymail);
MessageBox.Show("邮件发送成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}[/font][/font]
调式的时候全部过了 到 client.Send(mymail);这里就没有执行成功