如何从C#发送邮件 [英] How to send the mail from c#

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

问题描述

 System.Web.Mail.MailMessage oMailMessage = new MailMessage();
            oMailMessage.From = strFromEmaild;
            oMailMessage.To = strToEmailId;
            oMailMessage.Subject = strSubject;
            oMailMessage.Body = strBody;
            SmtpMail.SmtpServer = "localhost";
            SmtpMail.Send(oMailMessage);



(所有变量具有值)

(all variables have values)

我已经安装了SMTP虚拟服务。为什么它是无法发送电子邮件。为什么它不工作?

I have installed SMTP virtual services. why it is unable to send emails. why it is not working ??

修改

public bool SendMail(string strToEmailId, string strFromEmaild, string strSubject, string strBody)
{
    try
    {
        System.Web.Mail.MailMessage oMailMessage = new MailMessage();
        oMailMessage.From = strFromEmaild;
        oMailMessage.To = strToEmailId;
        oMailMessage.Subject = strSubject;
        oMailMessage.Body = strBody;
        SmtpMail.SmtpServer = "SERVERNAME";
        SmtpMail.Send(oMailMessage);

        return true;
     }
     catch (Exception ex)
     {
         return false;
     }
 }



我有这样的代码。它执行罚款,并返回true,但我没有收到在收件箱中的电子邮件。

I have this code. It is executing fine and is returning true, but I'm not getting any email in the inbox.

我发现,邮件只能发送到Gmail账户......为什么是?

I found that mail only can sent to gmail accounts... why it is?

推荐答案

确定错误是什么:

try
{
 SmtpMail.Send(oMailMessage);
}
catch (Exception ex)
{
//breakpoint here to determine what the error is:
Console.WriteLine(ex.Message);
}



从这里,请与异常细节编辑你的问题。

From here, please edit your question with that exception details.

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

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