无法从ASP.NET中的godaddy邮件服务器发送邮件

时间:2015-09-02 11:50:59

标签: asp.net email smtp smtpclient

我正在尝试使用带有SMTPClient的GoDaddy邮件服务器在ASP.NET中发送邮件,我的代码如下,我已经尝试了GoDaddy中的所有端口,但我无法发送邮件

我的代码:

    try
    {

        //Mail Message
        MailMessage mM = new MailMessage();
        //Mail Address
        mM.From = new MailAddress("xxx@sender.com");
        //receiver email id
        mM.To.Add("xxx@receiver.com");
        //subject of the email
        mM.Subject = "your subject line will go here";
        mM.Body = "Body of the email";
        mM.IsBodyHtml = true;
        //SMTP client

       SmtpClient sC = new SmtpClient();

        //credentials to login in to hotmail account
        sC.Credentials = new NetworkCredential(username, password);

        //port number for Hot mail
        sC.Port = 25;
        sC.Host = "smtpout.asia.secureserver.net";
        sC.UseDefaultCredentials = false;

        //enabled SSL
        sC.EnableSsl = false;
        sC.DeliveryMethod = SmtpDeliveryMethod.Network;

        sC.Timeout = 40000;

        //Send an email
        sC.Send(mM);

    }
    catch (Exception ex)
    {
        var temp = ex.Message;
    }

我还使用了端口号465和enablessl = true但没有成功

2 个答案:

答案 0 :(得分:0)

我也在努力解决这个问题。

问题是GoDaddy使用隐式SSL(SMTPS),而System.Net.Mail不支持此功能。 应该可以使用GoDady Relay帐户,但是每天只能发送250封电子邮件,发送的电子邮件将在接收方无法看到垃圾邮件!

然后我找到了一个开源库:http://sourceforge.net/projects/netimplicitssl/

您可以在Visual Studio中通过NuGet获取此包。 搜索: Aegis Implicit Mail 。 我可以告诉你,这很有效!

private void _SendEmail()
{
    try
    {
        var mail = "YourEmail@YourGoDaddyWebsite.com";
        var host = "smtpout.europe.secureserver.net";
        var user = "YourEmail@YourGoDaddyWebsite.com";
        var pass = "YourGoDaddyPassword!";

        //Generate Message 
        var message = new MimeMailMessage();
        message.From = new MimeMailAddress(mail);
        message.To.Add("receiver@website.com");
        message.Subject = "Subject Text...";
        message.Body = "Body Text...";

        //Create Smtp Client
        var mailer = new MimeMailer(host, 465);
        mailer.User = user;
        mailer.Password = pass;
        mailer.SslType = SslMode.Ssl;
        mailer.AuthenticationMode = AuthenticationType.Base64;

        //Set a delegate function for call back
        mailer.SendCompleted += compEvent;
        mailer.SendMailAsync(message);
    }
    catch (Exception ex)
    {
        string msg = ex.Message;
    }
}
private void compEvent(object sender, AsyncCompletedEventArgs e)
{
    if (e.UserState != null)
        Console.Out.WriteLine(e.UserState.ToString());

    Console.Out.WriteLine("is it canceled? " + e.Cancelled);

    if (e.Error != null)
        Console.Out.WriteLine("Error : " + e.Error.Message);
}

答案 1 :(得分:-1)

您应该注意,您不能发送非HTML或纯文本电子邮件。 message.IsBodyHtml成员目前似乎无法正常工作。