近期需要测试一个邮件服务器,先在自己电脑上测试一下。但苦于自己不会用命令行发邮件。怎样用命令行发邮件?网上搜了N多,找不到合适的答案。验证码是怎么回事啊?在哪里输入密码?好像auth login之类的命令不管用。 哪位大侠帮帮忙了,万分感谢telnet mx0.qq.com 25
220 new68.qq.com MX QQ Mail Server
helo qq.com
250 new68.qq.com
mail from:<[email protected]>
250 Ok
rcpt to:<[email protected]>
501 Bad address syntax.http://service.mail.qq.com/cgi-bin/help?id=29
rcpt to:<[email protected]>
250 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject:mail test
Hi,this is a successful mail.
.
550 Error: mail rejected by antispam server.http://service.mail.qq.com/cgi-bin/h
elp?id=29原字符 base64编码后的字符
[email protected] bWdjYzJAcXEuY29t
abc123 YWJjMTIz
[email protected] Y25oYXNjQHFxLmNvbQ==
220 new68.qq.com MX QQ Mail Server
helo qq.com
250 new68.qq.com
mail from:<[email protected]>
250 Ok
rcpt to:<[email protected]>
501 Bad address syntax.http://service.mail.qq.com/cgi-bin/help?id=29
rcpt to:<[email protected]>
250 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject:mail test
Hi,this is a successful mail.
.
550 Error: mail rejected by antispam server.http://service.mail.qq.com/cgi-bin/h
elp?id=29原字符 base64编码后的字符
[email protected] bWdjYzJAcXEuY29t
abc123 YWJjMTIz
[email protected] Y25oYXNjQHFxLmNvbQ==
标准协议
{
string MailCfgFile = "";
string MailSendAddress = "";
string SendAddressPwd = "";
string MailToAddress = "";
string MailContext = "";
string MailAttachFile = "";
string MailServerAddress = "";
string strLine = "";
StreamReader objReader; //获取当前路径
MailCfgFile = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
MailCfgFile += "mail.ini"; //读取文件
objReader = new StreamReader(MailCfgFile);
//读取发件人地址
strLine = objReader.ReadLine();
MailSendAddress = strLine;
//读取发件人的密码
strLine = objReader.ReadLine();
SendAddressPwd = strLine;
//读取收件人地址
strLine = objReader.ReadLine();
MailToAddress = strLine;
//读取文件内容
strLine = objReader.ReadLine();
MailContext = strLine;
//读取附件路径
strLine = objReader.ReadLine();
MailAttachFile = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
MailAttachFile += strLine;
//读取服务器IP地址
strLine = objReader.ReadLine();
MailServerAddress = strLine; //关闭文件
objReader.Close(); SendMailMethod(MailSendAddress, SendAddressPwd, MailToAddress, MailContext, MailAttachFile, MailServerAddress);
} //MailSendAddress ---表示发件人的地址
//SendAddressPwd ---表示发件人的密码
//MailToAddress ---表示收件人的地址
//MailContext ---表示邮件内容
//MailAttachFile ---表示邮件附件
//MialServerAddress ---表示服务器IP地址
private void SendMailMethod(string MailSendAddress,
string SendAddressPwd,
string MailToAddress,
string MailContext,
string MailAttachFile,
string MailServerAddress)
{
try
{
MailMessage mailmsg = new MailMessage();
//发信人地址
mailmsg.From = new MailAddress(MailSendAddress);
//收件人地址
mailmsg.To.Add(MailToAddress);
//
mailmsg.Subject = "Test Message"; //内容
mailmsg.Body = MailContext; //编码格式
mailmsg.BodyEncoding = System.Text.Encoding.UTF8;
mailmsg.IsBodyHtml = true;
//创建附件
string file = MailAttachFile;
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
mailmsg.Attachments.Add(data); SmtpClient sendmsg = new SmtpClient();
sendmsg.Host = MailServerAddress;
sendmsg.UseDefaultCredentials = false;
sendmsg.Credentials = new NetworkCredential(MailSendAddress, SendAddressPwd);
sendmsg.DeliveryMethod = SmtpDeliveryMethod.Network; sendmsg.Send(mailmsg);
mailmsg.Dispose();
data.Dispose();
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}