首页 新闻 会员 周边 捐助

4X200= 800分!!快来回答,超简单的问题!!发送邮件问题!

0
悬赏园豆:200 [已关闭问题]

在网上搜的代码会报错,无法发送邮件,

请哪高手试着向  zhangxinpingit@163.com  zhangxinpingit@yahoo.cn  zhangxinpingit@sina.com  zhangxinpingit@gmail.com  这几个邮箱上发一下邮件,内容就是 密码:aaa  就可以了,请高手们测试通过了后在把代码贴出来,十万火急!

万分感谢!

asp.net菜鸟的主页 asp.net菜鸟 | 初学一级 | 园豆:0
提问于:2009-03-25 13:41
< >
分享
其他回答(5)
0
winzheng | 园豆:8797 (大侠五级) | 2009-03-25 13:43
0

/// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="strSmtpServer">smtp服务器地址或者域名</param>
        /// <param name="strFrom">发件人</param>
        /// <param name="strFromPass">发件人密码</param>
        /// <param name="strto">收件人</param>
        /// <param name="strSubject">邮件标题</param>
        /// <param name="strBody">邮件内容</param>
        /// <param name="filePath">附件路径</param>
        public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody, string filePath)
        {
            System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(strFrom, strto, strSubject, strBody);
            if (File.Exists(filePath))
            {
                System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(filePath);
                string fileName = Path.GetFileName(filePath);
                attachment.Name = fileName;
                message.Attachments.Add(attachment);
            }
            //message.BodyEncoding = System.Text.Encoding.Default;
            //message.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
            message.IsBodyHtml = true;
           
            client.Send(message);
        }

 

我正在用的,因该没什么问题

小眼睛老鼠 | 园豆:2731 (老鸟四级) | 2009-03-25 14:39
0

一楼,貌似都是一个人发的

生鱼片 | 园豆:5757 (大侠五级) | 2009-03-25 16:03
0

using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;

 

#region 邮件激活
        /// <summary>
        /// 邮件发送
        /// </summary>
        /// <param name="mailNo">使用邮箱</param>
        /// <param name="mailNoPwd">使用邮箱密码</param>
        /// <param name="host">邮箱服务器</param>
        /// <param name="Port">邮箱服务器端口</param>
        /// <param name="mailto">用户邮箱</param>
        /// <param name="subject">邮箱主题</param>
        /// <param name="body">邮箱主体</param>
        public static void sendMail(string mailNo, string mailNoPwd, string host, int Port, string mailto, string subject, string body)
        {
            string guidStr = Guid.NewGuid().ToString();
            try
            {
                //string fromAddress = mailNo;          //发送人
                //string toAddress = mailto;            //接收人
                MailMessage mm = new MailMessage(mailNo, mailto);  //建立邮件
                mm.Subject = subject;        //邮件主题
                mm.Body = body;          //邮件主体               
                mm.IsBodyHtml = true;
                SmtpClient client = new SmtpClient();
                client.Host = host;
                client.Port = Port;
                client.Credentials = new System.Net.NetworkCredential(mailNo, mailNoPwd);
                client.Send(mm);
            }
            catch (Exception ex)
            {
                if (ex is SmtpException)
                {
                    ex.ToString();
                }
                else
                {
                }
            }
        }
        #endregion

 

 

使用:

SendMail.sendMail("xxxx@163.com", "密码", "mail.163.com", 25, Email, "职南针注册", http://www.u3w.com);

夏雷 | 园豆:165 (初学一级) | 2009-03-26 10:18
0

下面是vs2008中写的代码,测试成功,可以根据自己的需要稍作修改。如果是你是一的是.NET2.0,是不支持自带属性的,要把属性部分代码修改一下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;

namespace ISACA.Services.Common
{
public partial class MailEntity
{
/// <summary>
/// default constructor
/// </summary>
public MailEntity(){}

/// <summary>
/// Mail Entity constructor using 'GB2312' as default Encoding/timeout is 999999/IsHtmlBody is default as true
/// </summary>
/// <param name="mailFrom">the email address that will send the email</param>
/// <param name="userName">the name of the user who send the email</param>
/// <param name="pwd">the password of the user who send the email</param>
/// <param name="displaySenderName">the sender name</param>
/// <param name="mailTo">the receiver email address</param>
/// <param name="displayReceiverName">the receiver name</param>
/// <param name="subject">the subject of the email</param>
/// <param name="contentBody">the content of the email</param>
/// <param name="host">the host address that send email</param>
public MailEntity(string mailFrom, string userName, string pwd, string displaySenderName, string mailTo, string displayReceiverName, string subject, string contentBody, string host)
{
TimeOut
= 999999;
Encoding
= Encoding.GetEncoding("GB2312"); ;
MailFrom
= mailFrom;
UserName
= userName;
Pwd
= pwd;
DisplaySenderName
= displaySenderName;
MailTo
= mailTo;
DisplayReceiverName
= displayReceiverName;
Subject
= subject;
ContentBody
= contentBody;
Host
= host;
IsBodyHtml
= true;
}

/// <summary>
/// Mail Entity constructor
/// </summary>
/// <param name="timeOut">the email send timeout</param>
/// <param name="encoding">the Encoding type that will edcode the email content</param>
/// <param name="mailFrom">the email address that will send the email</param>
/// <param name="userName">the name of the user who send the email</param>
/// <param name="pwd">the password of the user who send the email</param>
/// <param name="displaySenderName">the sender name</param>
/// <param name="mailTo">the receiver email address</param>
/// <param name="displayReceiverName">the receiver name</param>
/// <param name="subject">the subject of the email</param>
/// <param name="contentBody">the content of the email</param>
/// <param name="host">the host address that send email</param>
/// <param name="isBodyHtml">if the content of the email is Html</param>
public MailEntity(System.Int32 timeOut, System.Text.Encoding encoding, string mailFrom, string userName, string pwd, string displaySenderName, string mailTo, string displayReceiverName, string subject, string contentBody, string host, System.Boolean isBodyHtml)
{
TimeOut
= timeOut;
Encoding
= encoding;
MailFrom
= mailFrom;
UserName
= userName;
Pwd
= pwd;
DisplaySenderName
= displaySenderName;
MailTo
= mailTo;
DisplayReceiverName
= displayReceiverName;
Subject
= subject;
ContentBody
= contentBody;
Host
= host;
IsBodyHtml
= isBodyHtml;
}

/// <summary>
/// Send mail
/// </summary>
/// <param name="mailEntity">MailEntity object</param>
/// <returns></returns>
public bool SendMail(MailEntity mailEntity)
{
try
{
Encoding encoding
= mailEntity.Encoding;
MailMessage mailMessage
= new MailMessage(new MailAddress(mailEntity.MailFrom, mailEntity.DisplaySenderName, encoding),
new MailAddress(mailEntity.MailTo, mailEntity.DisplayReceiverName, encoding));
mailMessage.SubjectEncoding
= encoding;
mailMessage.Subject
= mailEntity.Subject;
mailMessage.IsBodyHtml
= mailEntity.IsBodyHtml;
mailMessage.Body
= mailEntity.ContentBody;
SmtpClient smtpClient
= new SmtpClient(mailEntity.Host);
smtpClient.Credentials
= new NetworkCredential(mailEntity.UserName, mailEntity.Pwd);
smtpClient.Timeout
= mailEntity.TimeOut;
smtpClient.Send(mailMessage);
return true;
}
catch
{
return false;
}
}

#region Properties

/// <summary>
/// the email send timeout
/// </summary>
public Int32 TimeOut { set; get; }
/// <summary>
/// the email address that will send the email
/// </summary>
public String MailFrom { set; get; }
/// <summary>
/// the email address that will receive the email
/// </summary>
public String MailTo { set; get; }
/// <summary>
/// the Encoding type that will edcode the email content
/// </summary>
public Encoding Encoding { set; get; }
/// <summary>
/// the name of the user who send the email
/// </summary>
public String UserName { set; get; }
/// <summary>
/// the password of the user who send the email
/// </summary>
public string Pwd { get; set; }
/// <summary>
/// the sender name that will display in the sender item
/// </summary>
public String DisplaySenderName { set; get; }
/// <summary>
/// the receiver name that will display in the receiver item
/// </summary>
public String DisplayReceiverName { set; get; }
/// <summary>
/// mail content
/// </summary>
public String ContentBody { set; get; }
/// <summary>
/// mail subject
/// </summary>
public String Subject { set; get; }
/// <summary>
/// mail host address
/// </summary>
public String Host { set; get; }
/// <summary>
/// if the mail body is in html format
/// </summary>
public Boolean IsBodyHtml { set; get; }
#endregion
}
}
上不了岸的鱼 | 园豆:4613 (老鸟四级) | 2009-03-27 13:16
0

我自己封装了控件,你去下载www.mooloo.net,不用给我分呢,这问题问的

实在清闲 | 园豆:10 (初学一级) | 2009-04-01 15:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册