发送邮件程序,大家来帮忙。
private int SendMail(string Tomail)
{
MailMessage myMail = new MailMessage();
myMail.From = "fmtvlive@126.com ";
myMail.To = Tomail;
myMail.Subject = "1111111 ";
myMail.Priority = MailPriority.High;
myMail.BodyFormat = MailFormat.Text;
myMail.Body = "测试!!! ";
myMail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ", "1 ");
myMail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername ", "fmtvlive ");
myMail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword ", "fmtv2007 ");
SmtpMail.SmtpServer = "smtp.126.com ";
try
{
SmtpMail.Send(myMail);
}
catch
{
return 0;
}
return 1;
}
[解决办法]
SmtpMail.SmtpServer = "smtp.126.com ";
改成:
SmtpMail.SmtpServer= "IP地址 ";
不敢确定,试试吧
[解决办法]
public bool SendMail(string Accept_Mail_Add,string Send_Mail_Add, string mail_title, string mail_doby)
{
MailMessage myMail = new MailMessage(Send_Mail_Add ,Accept_Mail_Add );
myMail.Subject = mail_title;
myMail.Body = mail_doby;
myMail.IsBodyHtml = true;
//设置SMTP
SmtpClient client = new SmtpClient();
client.Host = "smtp.126.com ";
client.Port = 25;
client.Credentials = new System.Net.NetworkCredential( "郵件地址 ", "密碼 ");
client.Send(myMail);
return true;
}
[解决办法]
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient();
MailAddress address1 = new MailAddress( "你的邮箱地址 ");
mail.To.Add( "别人的邮箱地 ");
mail.From = address1;
mail.Subject = "Test ";
mail.Body = "Hello!!! ";
Attachment att = new Attachment(@ "D:\111.doc ");
mail.Attachments.Add(att);
mail.IsBodyHtml = true;
smtp.Host = "mail服务器地址 ";
smtp.Port = 25;
smtp.Credentials = new NetworkCredential( "你的邮箱地址 ", "密码 ");
smtp.Send(mail);
[解决办法]
試試
string s_from = TextBox1.Text;
string s_to = "***@126.com ";
string pwd = "*** ";
string dominoServerIP = "192.168.*.* ";
int i = s_from.IndexOf( "@ ");
string username = s_from.Substring(0, i);
MailAddress from = new MailAddress(s_from);
MailAddress to = new MailAddress(s_to);
MailMessage mailobj = new MailMessage(from, to);
mailobj.Subject = "test ";
mailobj.Body = "test ";
mailobj.IsBodyHtml = true;
mailobj.BodyEncoding = System.Text.Encoding.GetEncoding( "GB2312 ");
mailobj.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient(dominoServerIP);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(username, pwd);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
smtp.Send(mailobj);
Response.Write( " <script language= 'javascript '> alert( '發送成功 ') </script> ");
}
catch
{
Response.Write( " <script language= 'javascript '> alert( '發送失敗 ') </script> ");
}
[解决办法]
原因很简单,例如,你想发送给别人邮件,首先要知道别人的收件地址,此其一
很重要的是,其二,即你要发,你必须登陆自己的邮箱,你的代码中未出现登陆情况,所有就发不了,你设置好登陆名和密码登陆自己所使用的邮箱先,这样才能发送v
[解决办法]
public void MySendMail(string title,string content)
{
try
{
string t = title;
string c = content;
System.Net.Mail.SmtpClient cln = new System.Net.Mail.SmtpClient( "smtp.126.com ");
cln.UseDefaultCredentials = false;
cln.Credentials = new System.Net.NetworkCredential( "xxxxx@126.com ", "pwd ");//验证身份
cln.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;//指定邮件通过smtp服务器发送
MailMessage mes = new MailMessage( "xxxxx@126.com ", "yyyy@eee.com ", t, c);//邮件内容
mes.SubjectEncoding = Encoding.GetEncoding( "GB2312 ");
mes.BodyEncoding = Encoding.GetEncoding( "GB2312 ");
mes.IsBodyHtml = true;
cln.Send(mes);
}
catch (Exception ex)
{
}
}
[解决办法]
你看异常吧,CDO 访问错误