发送邮件失败 [英] Failure for sending mail
问题描述
我正在asp.net中发送邮件,它显示了一条很好的消息发送邮件失败".
我使用了这段代码,请在出现问题的地方帮帮我.
C#:
Hi,
I am sending mail in asp.net, it shows nice message "Failure sending mail".
I used this code, please help me where it goes wrong.
C#:
MailMessage mail = new MailMessage();
mail.From = new MailAddress("Rupesh@RUPI-PC");
mail.To.Add(new MailAddress("XXXXXX@gmail.com"));
mail.Subject="Testing";
mail.Body="testing the mail";
SmtpClient client = new SmtpClient();
client.host="localhost";
client.port=25;
try
{
client.Send(mail);
Response.Write("message sent successfully");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
在IIS for SMTP E-mail中,我提供了以下详细信息
电子邮件地址:Rupesh @ RUPI-PC
将电子邮件传递到SMTP服务器:选中使用localhost
"
端口= 25
身份验证设置:已选择不是必需的"
请建议我是否需要在SMTP电子邮件中提供更多详细信息
谢谢
Rupesh
In IIS for SMTP E-mail the following details i provided
Email Address: Rupesh@RUPI-PC
Deliver e-mail to SMTP server: checked the Use localhost
Port=25
Authentication settings : selected Not Required
Please Suggest me whether i need to provide any further details in SMTP e-mail
Thank You
Rupesh
推荐答案
在代码项目上尝试以下解决方案:-
如何在asp.net中自动发送邮件 [ ^ ]
任何人都可以告诉我在C#中自动发送电子邮件 [
Try this solution on codeproject:-
How to send mails automatically in asp.net[^]
can any body tell me the code for sending the emails automatically in C#[^]
SmtpClient client = new SmtpClient();
client.host="localhost";
client.port=25;
您是否在本地主机上运行SMTP服务器?我以为没有.
Do you have an SMTP server running on your local host? I thought not.
MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
MailMessage newmsg = new MailMessage ( mailfrom, mailto );
newmsg.Subject = "Subject of Email";
newmsg.Body = "Body(message) of email";
////For File Attachment, more file can also be attached
Attachment att = new Attachment ( "G:\\code.txt" );
newmsg.Attachments.Add ( att );
SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
smtps.UseDefaultCredentials = false;
smtps.Credentials = new NetworkCredential ( "mail@gmail.com", "pwd" );
smtps.EnableSsl = true;
smtps.Send ( newmsg );
这篇关于发送邮件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!