3

このコードはローカルで動作しますが、Godaddy のサーバーにアップロードすると、電子メールが送信されません。サーバーで機能しない理由はありますか? 何を変更する必要がありますか?

try {
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

    mail.From = new MailAddress("Myemail@gmail.com");
    mail.To.Add("Myemail@gmail.com");
    mail.Subject = "New sign up";
    mail.Body = "New member";

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("Myemail@gmail.com", "**Mypass**");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);
} catch(Exception ex) {
    throw ex;
}
4

4 に答える 4

2

Godaddyからホストされているサイト内から送信する場合は、いくつかのことを行う必要があります。リレーサーバーを使用してメッセージを送信します(これは開発マシンからは機能しません。アップロード後にライブでテストする必要があります)。これがリレーサーバー情報です。また、「差出人」アドレスが同じドメイン内の電子メールであることを確認してください。私は通常、toAddressと同じものを使用します。これが必要な理由については、こちらをご覧ください。

これは、Godaddy内のサイトから送信するために使用しているコードです。

        btnSend.Disabled = true;

        const string serverHost = "relay-hosting.secureserver.net";
        var msg = new MailMessage(toAddress, toAddress);
        msg.ReplyTo = new MailAddress(emailFrom);

        msg.Subject = subject;
        msg.Body = emailBody;
        msg.IsBodyHtml = false;

        try
        {
            var smtp = new SmtpClient();
            smtp.Host = serverHost;
            smtp.Credentials = new System.Net.NetworkCredential("account", "password");
            smtp.Send(msg);
        }
        catch (Exception e)
        {
            //Log the errors so that we can see them somewhere
        }
于 2011-12-19T02:36:02.380 に答える
2

They may be blocking outgoing SMTP connections in order to prevent spammers from using their service to send spam. You should check what error messages you're getting and check your server host's policy.

于 2011-12-19T01:22:11.450 に答える
0

You need to send your email via the godaddy smtp servers. I experienced the same issue with them before I think. I believe they give instructions of how to login via their FAQ.

于 2011-12-19T01:23:06.647 に答える
0

If you have ssh access to the server, try to telnet smtp.google.com via 25 and 465 ports also. If you get a timeout, then you're likely firewalled from connecting to these ports outside a certain IP range. Port 587 is for TLS. As you're using SSL, try port 465.

于 2011-12-19T01:23:52.937 に答える