无法发送MAILMESSAGE的在asp.net [英] Unable to send the mailmessage in asp.net

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

问题描述

以下code无法发送邮件的客户,它不抛出任何异常。在code它不会发送任何电子邮件或异常,但executed.I是全新的关于asp.net。有些人可以帮助我如何解决这个问题。

code:

 尝试
{
    字符串username =拉梅什;
    字符串密码=123456;
    字符串的发送方=ramesh@gmail.com;
    字符串recer =customer@yahoo.com;
    字符串主题=Comformation;
    绳体=尊敬的客户;    MAILMESSAGE msgMail = MAILMESSAGE新(的发送方,recer,主题,正文);    INT =会将PortNumber 25;
    SmtpClient SMTP =新SmtpClient(smtp.test.com,会将PortNumber);
    msgMail.IsBodyHtml =真;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials =新System.Net.NetworkCredential(用户名,密码);    smtp.Send(msgMail);    MsgLP.Text =通过电子邮件发送给客户。;
    LogInLink.Visible = TRUE;
}
赶上(例外前){
    AuditLog.LogError(ErrorE邮件+ ex.Message);
}


解决方案

您必须设置 smtp.EnableSsl = TRUE 和使用端口号 587 。您的最终code将是这样的:

 尝试
{
字符串username =拉梅什;
字符串密码=123456;
字符串的发送方=ramesh@gmail.com;
字符串recer =customer@yahoo.com;
字符串主题=Comformation;
绳体=尊敬的客户;MAILMESSAGE msgMail = MAILMESSAGE新(的发送方,recer,主题,正文);INT =会将PortNumber 587; //改变端口号587
SmtpClient SMTP =新SmtpClient(smtp.gmail.com,会将PortNumber); //从测试更改到Gmail
smtp.EnableSsl = TRUE; //设置EnableSsl为true
msgMail.IsBodyHtml =真;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials =新System.Net.NetworkCredential(用户名,密码);
smtp.Send(msgMail);
MsgLP.Text =通过电子邮件发送给客户。;
LogInLink.Visible = TRUE;
}
赶上(例外前){
AuditLog.LogError(ErrorE邮件+ ex.Message);
}

我测试code。与我的凭据并能正常工作。

The following code unable to send an emails to customers and it not throwing any exception. The code it not send any email or exception but executed.I am completely new about the asp.net. Some one can help me how to resolve the problem.

Code:

try
{
    String userName = "ramesh";
    String passWord = "123456";
    String sendr = "ramesh@gmail.com";
    String recer = "customer@yahoo.com";
    String subject = "Comformation ";
    String body = "Dear Customer";

    MailMessage msgMail = new MailMessage(sendr, recer, subject, body);

    int PortNumber = 25;
    SmtpClient smtp = new SmtpClient("smtp.test.com", PortNumber);
    msgMail.IsBodyHtml = true;                                     
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new System.Net.NetworkCredential(userName, passWord);

    smtp.Send(msgMail);

    MsgLP.Text = "Emailed to Customer..";
    LogInLink.Visible = true;
}
catch (Exception ex){
    AuditLog.LogError("ErrorE-mail " + ex.Message);
}

解决方案

You have to set smtp.EnableSsl=true and use port number 587. Your final code will be this:

try
{
String userName = "ramesh";
String passWord = "123456";
String sendr = "ramesh@gmail.com";
String recer = "customer@yahoo.com";
String subject = "Comformation ";
String body = "Dear Customer";

MailMessage msgMail = new MailMessage(sendr, recer, subject, body);

int PortNumber = 587; //change port number to 587
SmtpClient smtp = new SmtpClient("smtp.gmail.com", PortNumber); //change from test to gmail
smtp.EnableSsl = true; //set EnableSsl to true
msgMail.IsBodyHtml = true;                                     
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential(userName, passWord);
smtp.Send(msgMail);
MsgLP.Text = "Emailed to Customer..";
LogInLink.Visible = true;
}
catch (Exception ex){
AuditLog.LogError("ErrorE-mail " + ex.Message);
}

I tested this code with my credentials and it works fine.

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

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