日期:2014-05-19  浏览次数:20478 次

发邮件问题,兄弟们进
我用asp.net发邮件(网上很多相关代码),但全都不能用gmail发送或者用gmail接收。不知道哪位有好的办法。
要用using   System.Net.Mail;


------解决方案--------------------
接收邮件 (POP3) 服务器 - 需要 SSL: pop.gmail.com
使用 SSL:是
端口:995
发送邮件 (SMTP) 服务器 - 需要 TLS: smtp.gmail.com(使用验证)
使用验证:是
使用 STARTTLS:是(某些客户端称其为 SSL)
端口:465 或 587
帐户名: 您的 Gmail 用户名(包括 @gmail.com)
电子邮件地址: 您的完整 Gmail 电子邮件地址(用户名@gmail.com)
密码: 您的 Gmail 密码

------解决方案--------------------
MailMessage msg = new MailMessage();
msg.From = lblFrom.Text;
msg.Bcc = txtEmailName.Text;
msg.Subject = txtEmailSubject.Text.Trim();
msg.Body = txtContent.Text.Trim().Replace( " <br> ", "\r\n ");
msg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ", "1 " );
msg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername ", lblMailServerUserName.Text);
msg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword ", lblMailServerPassWord.Text);
msg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpserverport ", lblport.Text);
if(lblssl.Text.Equals( "true "))
msg.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpusessl ", "1 ");
SmtpMail.SmtpServer = lblSmtp.Text;
foreach( ListItem temp in AffixList.Items )
{
if( temp != null )
{
string attachFile=temp.Value;
MailAttachment mailAttach=new MailAttachment(attachFile);
msg.Attachments.Add(mailAttach);
}
}
try
{
SmtpMail.Send(msg);
utility.Method.ExampleJavascript(Page, "發送成功! ", "EmailSend.aspx ");
}
catch
{
utility.Method.ExampleJavascript(Page, "發送失敗,請檢查您填寫的信箱地址! ",true);
}
finally
{
delFile();
msg = null;
}
------解决方案--------------------
我用这个发 没问题

//Builed The MSG
MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add( "toaddress@gmail.com ");
msg.From = new MailAddress( "fromaddress@gmail.com ", "from ", System.Text.Encoding.UTF8);
msg.Subject = "subject ";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "body ";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;

//Add the Creddentials
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential( "username ", "password ");
client.Port = 587;//or use 587
client.Host = "smtp.gmail.com ";
client.EnableSsl = true;
//client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
//object userState = msg;
try
{
//you can also call client.Send(msg)
//client.SendAsync(msg, userState);
client.Send(msg);
}
catch (System.Net.Mail.SmtpException ex)
{
Response.Write(ex.ToString());
}

------解决方案--------------------
http://www.codeproject.com/useritems/SendMailUsingGmailAccount.asp
------解决方案--------------------