简体   繁体   中英

GoDaddy forwarding email with SMTP and WebMail in ASP.NET C#

I'm writing a simple Contact form for a website and need to post the contents of the form to a forwarding email using WebMail in ASP.NET. I used the guide the Microsoft Documentation provides found here-> Sending Email from an ASP.NET Web Pages (Razor) Site .

The form posts to a new page called ProcessRequest.cshtml just like the documentation shows, which should send the message with WebMail using SMTP to the forward email address that I provide, which would then forward on to me.

When I run my code, I eventually get the error message: The operation has timed out. on the ProcessRequest.cshtml page along with the email that would be sent (so I know the form is being posted back to the server and accessible, it's just not getting from my form to the forwarding account.

I think the problem is either the settings for the WebMail helper, my GoDaddy account, or the fact that I'm trying to test it on localhost and not live. Of course Godaddy is of no help. Here is the form:

    <div class="card white-background-area ">
        <form  method="POST" action="ProcessRequest.cshtml">
            <fieldset>
                <div class="form-group">
                    <label for="name">Name: *</label>
                    <input type="text" class="form-control" id="name" placeholder="Enter Your Name" name="name" required>
                </div>
                <div class="form-group">
                    <label for="email">Email address: *</label>
                    <input type="email" class="form-control" id="email" placeholder="Enter email" name="email" required>
                </div>
                <div class="form-group">
                    <label for="question">Enter your question here: *</label>
                    <textarea class="form-control" name="question" id="question"></textarea>
                </div>
                <div class="mb-5">
                    <button type="submit" class="btn btn-primary">Submit</button>
                    <button type="reset" class="btn btn-primary">Reset</button>
                </div>

                <p>* = required</p>
            </fieldset>
        </form>
    </div>
</div>

Here is the ProcessRequest.cshtml page:

    ViewBag.Title = "ProcessRequest.cshtml";
    var name = Request["name"];
    var email = Request["email"];
    var message = Request["question"];
    var errorMessage = "";
    var debuggingFlag = true;
    try
    {
        // Initialize WebMail helper
        WebMail.SmtpServer = "smtpout.secureserver.net";
        WebMail.SmtpPort = 465;
        WebMail.From = "forwardingemail@url.com";

        // Send email
        WebMail.Send(to: email,
            subject: "Help request from - " + name,
            body: message
        );
    }
    catch (Exception ex)
    {
        errorMessage = ex.Message;
    }
}
<!DOCTYPE html>
<html>
<head>
    <title>Request for Assistance</title>
</head>
<body>
    <p>Sorry to hear that you are having trouble, <b>@name</b>.</p>
    @if (errorMessage == "")
    {
        <p>
            An email message has been sent to our customer service
            department regarding the following problem:
        </p>
        <p><b>@message</b></p>
    }
    else
    {
        <p><b>The email was <em>NOT</em> sent.</b></p>

        <p>This email would contain:</p>
        <p>@name</p>
        <p>@email</p>
        <p>@message</p>

        <p>
            Please check that the code in the ProcessRequest page has
            correct settings for the SMTP server name, a user name,
            a password, and a "from" address.
        </p>
        if (debuggingFlag)
        {
            <p>The following error was reported:</p>
            <p><em>@errorMessage</em></p>
        }
    }
</body>
</html>

Thank you in advance for helping me with this.

I finally got through to someone at godaddy who said I can't use a forwarding address for a contact form because it's a form of spoofing and I don't actually have a password and username for the account to use for webmail. So it looks like it has to be a regular email. Can't be done with a forwarding email through godaddy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM