如何不通过主机的SMTP设置发送电子邮件?

时间:2019-05-30 21:39:48

标签: c# asp.net asp.net-mvc email hosting

我在Hostgator上托管了一个网站,并带有InMotion上的DNS。我正在尝试使用Inmotion电子邮件帐户发送电子邮件。在本地运行正常,但是在主机上时出现“无法发送邮件”的信息。

我已完全禁用Hostgator上的DNS区域,因此该域的唯一记录来自Inmotion,这完全正常。

即使我告诉我不要,它似乎仍在尝试默认为我的主机。我想念什么?

public string SendEmail(string fromEmail, string emailSubject, string emailBody, string emailerName, string emailerTelephone, string emailDate)
        {
        string senderEmail = "email";
        string senderPassword = "password"; 
        MailMessage message = new MailMessage(senderEmail, "toemail")
        {
            Subject = emailerName + " is contacting you about " + emailDate,
            Body = emailBody + "<br><br>" + emailerName + "'s Email is " + fromEmail + "<br><br>" + emailerName + "'s Phone is " + emailerTelephone,
            BodyEncoding = Encoding.UTF8,
            IsBodyHtml = true,

        };
        SmtpClient client = new SmtpClient();
        NetworkCredential NetworkCred = new NetworkCredential(senderEmail, senderPassword);
        //System.Net.NetworkCredential basicCredential = new System.Net.NetworkCredential(senderEmail, senderPassword);
        client.EnableSsl = false;
        client.UseDefaultCredentials = false;
        client.Credentials = NetworkCred;
        client.Port = 587;
        client.Host = "webmail.steadystatestudios.com";

        try
        {
            client.Send(message);
            return "Success";
            //return true;
        }

        catch (Exception ex)
        {
            return ex.Message;
        }
}

我尝试使用网络邮件,邮件,仅域和Inmotion的安全选项,但是它们都无法在我的主机上正常工作。

如果有区别的话,我正在通过Ajax调用它。

0 个答案:

没有答案