邮件发送 [英] mail sending

查看:111
本文介绍了邮件发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Name space:
using System.Web.Mail;  
    MailMessage mail = new MailMessage();
        mail.To = "a@gmail.com";
        mail.From = "admin@adminio.com";
        mail.Subject = "Confirmation";
        mail.Body = "Acoount confirmed....................";
        SmtpMail.SmtpServer = "1:1:1:1";

        try
        {
            SmtpMail.Send(mail);
            Response.Write("Mail send successfully");
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }




发生错误:
传输无法连接到服务器.

此错误的原因是什么?

给我正确的问题,请

[已编辑]代码被包装在前置"标签中[/已编辑]




Error occured:
The transport failed to connect to the server.

what is the reason for this error?

give me the correct problem, please

Code is wrapped in "pre" tags[/Edited]

推荐答案

检查防火墙并确保未阻止防火墙您希望从中发送电子邮件的端口.
Check for firewall and make sure it is not blocking the port from which you wish to send the email.


您正在尝试从相当长的一段时间开始使用此功能.

可能是由于各种原因.您需要一一看待它们.
港口开放吗?防火墙权限到位了吗?
进一步确保已在Web.Config中配置SMTP配置:
You are trying to have this feature from quite some time now.

It can be because of various reasons. You need to look at them one by one.
Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>


如果需要,请查看此Microsoft Video教程:
使用ASP.NET发送来自网站的电子邮件 [


If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]


public bool SendEmail(string senderEmail, string receiverEmail, string subject, string body)
{
try
{
//MailAddress emailto = senderEmail;
MailAddress emailto = new MailAddress(receiverEmail);
//MailAddress emailfrom = receiverEmail;
MailAddress emailfrom = new MailAddress(senderEmail);
MailMessage mail = new MailMessage(senderEmail, receiverEmail);
mail.Subject = subject;

mail.Body = body;
mail.IsBodyHtml = true;
NetworkCredential basicCredential = new NetworkCredential("UserName", "Password");
SmtpClient objSmtpClient = new SmtpClient(HostAddress,PortNo);

objSmtpClient.Credentials = basicCredential;



objSmtpClient.Send(mail);
}
catch
{
return false;
}
return true;
}





停止防火墙访问保护





stop firewall access protection


这篇关于邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆