Sending Mail from Windows Azure Service, using God

2019-07-03 21:54发布

With the following settings I have not been able to send mails from local PC. Having searched stack overflow for many responses -

  1. I tried swapping host from smtpout.secureserver.net to relay-hosting.secureserver.net. Which didn't help. (Probably because relay-hosting has to be used when hosting on godaddy server) My host is windows azure service..
  2. I read on SO that defaultCredentials & enableSSL is mutually exclusive. Please suggest.
  3. Port 25 may be blocked by several ISP, so as an alternative port 80 could be used for sending mail using http.
  4. System.net.Mail doesn't support godaddy's 465 port for https.

Having tried all these possibilities, I end up with either of the two errors -

  1. Failure sending Mail - Unable to connect with remote server.
  2. The SMTP server requires a secure connection or the client was not authenticated.

Question 1. Please suggest precisely, what piece of configuration do I need to use godaddy smtp server from Windows Azure service?

From localhost I am trying to enable self-signed certificate, as suggested by Scott, here..

http://weblogs.asp.net/scottgu/archive/2007/04/06/tip-trick-enabling-ssl-on-iis7-using-self-signed-certificates.aspx

Question 2. specifying from address in web.config, seems redundant, since in MailMessage we're bound to enter from address once again. What is its purpose ?

What the easiest way to configure Azure to configure IIS to use azure service to

    private void SendMail(MailMessage msg)
    {
        try
        {
            var smtp = new SmtpClient();
            smtp.Send(msg);
        }
        catch (SmtpFailedRecipientException exFailed)
        {
            lblExSendMail.Text = exFailed.Message;
        }
    }

<system.net>
<mailSettings>
  <smtp deliveryMethod="Network" from="xyz@xyz.com">
    <network host="smtpout.secureserver.net" port="80" userName="xyz@xyz.com" password="xyz-password" />
  </smtp>
</mailSettings>

3条回答
趁早两清
2楼-- · 2019-07-03 22:06

Sending email from Windows Azure Application using 3rd party SMTP server does not need any special configuration on either parties, Windows Azure or 3rd party SMTP server. Most of SMTP server are set to use port 25 which is easiest way to send email from Windows Azure and GoDaddy SMTP server is also set to use port 25 so you sure can do it easily. No SSL/certifcate configuration is needed on any side.

Following code snippet is the simplest code you can use either in C# app or in Windows Azure directly without any configuration eith goDaddy SMTP service:

SmtpClient MySMTPClient;
MailMessage myEmail;
MySMTPClient = new SmtpClient("smtp.secureserver.net", 25);
MySMTPClient.Credentials = new NetworkCredential("<MailID>", "<Password>");
myEmail = new MailMessage(new MailAddress("<sender>"), new MailAddress("<receiver>"));
myEmail.Body = "Email from Windows Azure Application";
myEmail.Subject = "Email from Windows Azure";
try
{
  MySMTPClient.Send(myEmail);
}
catch (Exception ex)
{
  // Display Exception Details
} 
查看更多
疯言疯语
3楼-- · 2019-07-03 22:13

That is so simple:

You must focus on smtp host, port, ssl... Change smtp host to: relay-hosting.secureserver.net And DELETE port and ssl, thats all... Do not use smtp port and smtp ssl true or false

    var fromAddress = "mailfrom@yourdomain";
    // any address where the email will be sending
    var toAddress = "mailto@yourdomain";
    //Password of your mail address
    const string fromPassword = "******";
    // Passing the values and make a email formate to display
    string subject = TextBox1.Text.ToString();
    string body = "From: " + TextBox2.Text + "\n";
    body += "Email: " + TextBox3.Text + "\n";
    body += "Subject: " + TextBox4.Text + "\n";
    body += "Message: \n" + TextBox5.Text + "\n";
    // smtp settings
    var smtp = new System.Net.Mail.SmtpClient();
    {
        smtp.Host = "relay-hosting.secureserver.net";
**//Warning Delete =>//smtp.Port = 80;**
**//Warning Delete =>//smtp.EnableSsl = false;**
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 20000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);

That works on Godaddy Windows Host on target Framework 4.0

查看更多
啃猪蹄的小仙女
4楼-- · 2019-07-03 22:27
  1. Ans 1. Port 80 instead of using 25 did work for me for sending mails using http channel. This worked for both local and Windows Azure. Prevent yourself from specifying anything else in network element smtp, apart from host, port=80, userName and password-->for http.

  2. Ans 2. From attribute of smtp element in web.config is used by parameterless constructor of MailMessage. This is particularly useful when you are going to send mail by common email address.

查看更多
登录 后发表回答