If anybody can help me out for writing Email component for sending mails .
I have used following code but unable to send mails .Let me know If you have any solution.
C#,vb.net,MVC,Jquery,javascript,jscript,vbscript,html,vb,sharepoint,COM,WPF,WCF,Wwf,Asp,Asp.net,questions & answers,
Getting error when I try to execute GET Method, TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD met...
Hello, my name is Monikandan. I'm a 40 year old self-employed ML Group from the Nagercoil.
Learn More →
SOLUTION 1:
ReplyDeleteI have worked on similar kind of task for generating the mail and send using “Microsoft.Office.Interop.Outlook.Application“.
Hope this may help you .
Please let me know in case any assistance required.
Piece of Code :
using System.Net.Mail;
using Microsoft.Office.Interop.Outlook;
Microsoft.Office.Interop.Outlook.Application OAPP = new Microsoft.Office.Interop.Outlook.Application();
// Create a new AppointmentItem.
MailItem mailItem = OAPP.CreateItem(OlItemType.olMailItem);
mailItem.To = "p.prakash@xxx.com";
mailItem.CC = "p.prakash@xxx.com";;
mailItem.Subject = "Subject of mail";
mailItem.BodyFormat = OlBodyFormat.olFormatHTML;
mailItem.HTMLBody = "Mail contents";
//mailItem.Send(); // To send the mail directly to the mailid in TO, CC
mailItem.Display(true); // Will open the mail content in outlook to see,edit and send.
SOLUTION 2:
--------------------------------------------------------------------------------
Please try this solution, The outlook client should be in the running status.
string strBody = string.Empty;
Outlook.Application Oapp = new Outlook.Application();
Outlook.MailItem Omail = (Outlook.MailItem)Oapp.CreateItem(Outlook.OlItemType.olMailItem);
Omail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
Omail.HTMLBody = strBody;
Omail.Subject = “Type your subject here”;
Outlook.Recipients Orecips = (Outlook.Recipients)Omail.Recipients;
Outlook.Recipient Orecip = (Outlook.Recipient)Orecips.Add(strEmails[i]);
Orecip.Resolve();
Omail.Send();
Orecip = null;
Orecips = null;
Omail = null;
Oapp = null;
Thanks,
Iyyappan.
SOLUTION 3:
Please try the following code :-
using System.Net.Mail;
System.Net.Mail.MailMessage msgMail = new System.Net.Mail.MailMessage();
System.Net.Mail.MailAddress from = new MailAddress(p.prakash@xxx.com);
System.Net.Mail.MailAddress to = new MailAddress(p.prakash@xxx.com);
msgMail = new System.Net.Mail.MailMessage(from, to);
msgMail.CC.Add(p.prakash.gawas@xxx.com);
msgMail.Subject = "CSTShipExtract Error ";
msgMail.IsBodyHtml = false;
msgMail.Body = "Error occurred inserting shipment. SONumber = " + sh.SOIdentity.OrderNumber + ". Error is " + ex4.Message + "\r\n";
System.Net.Mail.SmtpClient smtpclient = new System.Net.Mail.SmtpClient("mailhost.lss.emc.com");
smtpclient.Send(msgMail);