Emails are not getting delivered.
Hi,
I am developing the Email sending code for one of my WCF service in project. The code is as followed:
[OperationContract]
[WebInvoke(Method =
"POST"
, RequestFormat = WebMessageFormat.Json, UriTemplate =
"/CommonServices/LocationService.svc/Send"
)]
public
string
SendCarrerFormEmailConfirmation(CarrerFormViewModel _carrerFormData)
string
strResult =
""
;
try
string
fromEmail =
""
;
EmailData _email =
new
EmailData();
_email.EmailSubject =
"Loan Centers – Careers"
;
_email.EmailBody =
"This is Email Body"
;
var dynamicModuleManager = DynamicModuleManager.GetManager();
Type showcaseType = TypeResolutionService.ResolveType(
"Telerik.Sitefinity.DynamicTypes.Model.AdminSettings.AdminParameters"
);
// This is how we get the collection of ContentPage items
var showcases = dynamicModuleManager.GetDataItems(showcaseType).Where(
"ParameterName == @0"
,
"CareerFormAdminEmail"
).Where(s => s.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
_email.ToEmailID =
"testdev@website.co.in"
;
if
(showcases.Any())
_email.ToEmailID = showcases.FirstOrDefault().GetValue(
"ParameterValue"
).ToString();
var manager = ConfigManager.GetManager();
var smtpSettings = Config.Get<SystemConfig>().SmtpSettings;
MailMessage message =
new
MailMessage();
message.From =
new
MailAddress(smtpSettings.UserName);
message.To.Add(
new
MailAddress(_email.ToEmailID));
message.Subject = _email.EmailSubject;
message.Body = _email.EmailBody;
message.IsBodyHtml =
true
;
message.BodyEncoding = Encoding.Unicode;
message.SubjectEncoding = Encoding.Unicode;
//The below code is not working for Sending Emails
EmailSender.Get().Send(message);
//mark as sent ok
strResult =
"Sucess"
;
catch
strResult =
"Error"
;
return
strResult;
On line EmailSender.Get().Send(message); there is no error/exception, but Email is not Delivered.
I have Set the SMTP Credentials as mentioned on site's tutorials.
If I debug the code It contains all the SMTP Info (It's correct & working fine in my other website).
Also, If you could help me about how to Access this WCF service using JavaScript Ajax, as By using JavaScript Ajax I am getting error in post method/ but in Get Method I can access other Services.
Thanks
Hi,
Can you please try the following code in order to send your e-mails:
var manager = ConfigManager.GetManager();
string
smtpHost = manager.GetSection<SystemConfig>().SmtpSettings.Host;
int
smtpPort = manager.GetSection<SystemConfig>().SmtpSettings.Port;
var smtpClient =
new
SmtpClient(smtpHost, smtpPort);
var message =
new
MailMessage(
"soma@mail.com"
,
"ivand.dimitrov@telerik.com"
)
Subject =
"Hi"
,
Body =
"test"
;
smtpClient.Send(message);