在windowform里面发邮件
我想在窗体里面实现发邮件的功能,用的是System.Net.Mail.MailMessage和System.Net.SmtpClient对象,在System.Net.StmpClient里面要设置发邮件的服务器,我有163的油箱,可是我不知道在System.Net.StmpClient里面怎样填写163的服务器,有谁知道我该怎么写?
还有个问题,就是本地机器如果有stmp了,我就可以发邮件了么?
------解决方案--------------------MailMessage Mail = new MailMessage();
Mail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ", "1 ");
Mail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout ", 60);
Mail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername ", "你的邮箱名 ");
Mail.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword ", "密码 ");
Mail.From = m_FromUser;
Mail.To = m_ToUser;
Mail.Cc = m_CCUser;
Mail.Subject = m_Subject;
Mail.Body = m_Body;
Mail.BodyFormat = MailFormat.Html;
foreach(string AttachmentPath in m_AttachmentPath)
{
MailAttachment Attachment = new MailAttachment(AttachmentPath,MailEncoding.Base64);
Mail.Attachments.Add(Attachment);
}
SmtpMail.SmtpServer = "这里填smtp.163.com ";
SmtpMail.Send(Mail);
------解决方案--------------------/// <summary>
/// Sending eMail using System.Net.Mail
/// </summary>
/// <param name= "users "> The User parameters
/// <example>
/// string[] users = new string[]{ "smtp.163.com ", "Your 163 Account ", "Your 163 Account Password "};
/// </example>
/// </param>
/// <param name= "receiver "> The eMail Receiver </param>
/// <param name= "sender "> The eMail Sender </param>
/// <param name= "subject "> The eMail Subject </param>
/// <param name= "msg "> The eMail Body </param>
public void SendeMail(string[] users, string receiver, string sender, string subject, string msg)
{
MailMessage eMail = new MailMessage(sender, receiver);
eMail.Subject = subject;
eMail.BodyEncoding = Encoding.UTF8;
eMail.SubjectEncoding = Encoding.UTF8;
eMail.Body = msg;
try
{
SmtpClient smtp = new SmtpClient();
smtp.Host = users[0];
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential(users[1], users[2]);
smtp.Send(eMail);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
------解决方案--------------------去下载个jmail
然后里面有个dll文件,引用这个文件。
代码如下:
using jmail;
public void Send_Email(string strCharset,string strForm,string strFormName,string strUserName,string strUserPwd,byte iPriority,string strEmail,string strAttachment,string strSubject,string strBody,string strMailServer)
{
tinghai: try
{
bool TempBool = false;
TempJmail = new MessageClass();
TempJmail.Charset = strCharset; //字体
TempJmail.From = strForm;
TempJmail.FromName = strFormName;
TempJmail.MailServerPassWord = strUserPwd;
TempJma