Sitefinity Send Email Works only Local machine not in server
Hi All,
I'm trying to send Email in sitefinity 6.2 but it works only local machine not in live server (windows server 2012)
Method 1:
public
void
Sendmail(
string
toEmail)
try
MailAddress fromAddress =
new
MailAddress(
"abc@gmail.com"
);
MailAddress toAddress =
new
MailAddress(toEmail);
string
subject =
"Mail Subject"
;
string
body =
"Mail Body"
;
EmailSender smtp = EmailSender.Get();
using
(MailMessage message =
new
MailMessage(fromAddress, toAddress)
Subject = subject,
IsBodyHtml =
true
,
Body = body
)
smtp.TrySend(message);
catch
(Exception ex)
MessageBox.Show(ex.ToString());
Method 2:
public
void
Sendmail1(
string
toEmail)
try
SmtpClient smtpClient =
new
SmtpClient(
"smtp.gmail.com"
, 587);
smtpClient.Credentials =
new
System.Net.NetworkCredential(
"MyEmailID@gmail.com"
,
"gmailPassword"
);
smtpClient.UseDefaultCredentials =
true
;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl =
true
;
MailMessage mail =
new
MailMessage();
//Setting From , To and CC
mail.From =
new
MailAddress(
"MyEmailID@gmail.com"
,
"MyWeb Site"
);
mail.To.Add(
new
MailAddress(
"info@abc.com"
));
smtpClient.Send(mail);
catch
(Exception ex)
MessageBox.Show(ex.ToString());
These Two Methods are working in local Machine Perfectly ,
Thanks in Advance
Hi Ajay,
The code you're showing here does not depend on Sitefinity. Is your host Arvixe by any chance? I had a similar issue a few months ago. Arvixe is using implicit SSL to allow connections to their hMailServer (explicit SSL is not supported yet by hMailServer). The Microsoft system.net.mail component does not support this though. The only way Microsoft supports this is through their obsolete system.web.mail, which I did not want to use. I choose to use an external SMTP server to get around this.
If this is indeed the same problem, then email sent from within Sitefinity (such as account confirmation emails) will fail as well. You can't change the Sitefinity code though, so an external server is the way to go there as well.