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

查看:116
本文介绍了如何从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);

(所有变量都有值)

我已经安装了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;
     }
 }

我有这个代码。

我发现邮件只能发送到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天全站免登陆