With the following settings I have not been able to send mails from local PC. Having searched stack overflow for many responses -
- 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..
- I read on SO that defaultCredentials & enableSSL is mutually
exclusive. Please suggest.
- Port 25 may be blocked by several ISP, so as an alternative port 80
could be used for sending mail using http.
- 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 -
- Failure sending Mail - Unable to connect with remote server.
- 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>
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
}
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