This question already has an answer here:
How I can transform my C# code : System.Web.Mail" transform by "System.Net.Mail"
(1 answer)
Closed 8 years ago.
I need some help converting System.Web.Mail to System.Net.Mail to help
send out e-mail notifications appropriately on some forms.
The old code snippet used is below:
MailMessage NotificationEmail = new MailMessage();
NotificationEmail.BodyFormat = MailMessage.IsBodyHtml;
NotificationEmail.From = "RCHIPM#ttuhsc.edu";
//NotificationEmail.To = user;
NotificationEmail.To = "RCHIPM#ttuhsc.edu";
NotificationEmail.Subject = "Notification : ";
NotificationEmail.BodyFormat = MailFormat.Html;
And some of the errors I'm getting include:
1.) 'System.Net.Mail.Message' does not contain a definition for 'BodyFormat' and no extension method 'BodyFormat' accepting a first argument of type 'System.Net.Mail.MailMessage' could be found.
2.) An object reference is required for the non-static field, method, or property 'System.Net.Mail.MailMessage.IsBodyHTML.get'
3.) Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress
4.) Property or indexer 'System.Net.Mail.MailMessage.To' cannot be assigned to -- it is read only.
...amongst other similar errors going on as well.
I'm quite certain most of these are inter-related to the main problem that I'm trying to solve which is just trying to convert the systems use of System.Web.Mail to System.Net.Mail.
I've done all the MVC and Telerik Updates I possibly could through NuGet, so those are up-to-date. I've Updated all the references as well so I know that's no longer an issue.
There may be a few things I need to change on Web.Config, but I'm not quite too sure what should be added or modified to it. I'm always weary of editing system files and assemblies, and people's tips on them as well so I try to avoid making those changes unless they are absolutely necessary.
Currently I'm using both System.Web.Mail and System.Net.Mail at the top of the file so it currently reads:
using System.Web.Mail;
using System.Net.Mail;
...as part of it's library includes.
The system uses .NET Framework 4 by the way. Should I try updating it to
.NET Framework 4.5?
Does anyone have any possible solutions for updating this block of code?
It looks like from searching through here that a bunch of people are having similar issues, but everyone's questions appear to have mixed results/answers from forum moderators.
So that's why I submitted this question just to see what kind of responses I'd get.
Hopefully, this is enough information for you guys.
If not, please let me know if you need additional info so I can provide it for you.
Thanks!
There are a couple of issues with your usage. This is how html emails are usually sent:
var mail = new MailMessage();
//set address (not just a string)
mail.From = new MailAddress("RCHIPM#ttuhsc.edu");
mail.To.Add("destination#destination.com");
//set the subject
mail.Subject = "This is the subject";
//set the body
mail.Body = "some html <b>in</b> here".
mail.IsBodyHtml = true;
//send the message
var smtp = new SmtpClient("127.0.0.1"); // Loopback address
smtp.Send(mail);
Related
I am developing one tool to keep track of emails and would like to trace the emails undelivered to sender.
I dont want to use any third party tool or any external reference
What I have tried?
-To read report Item but Body is in Chinese like language
-Googled on some solutions but nothing is working i.e. solution is related to
//PR_TRANSPORT_MESSAGE_HEADERS
link to get property name "http://schemas.microsoft.com/mapi/proptag/0x0C1A001F"
outlook PropertyAccessor class
PropName link is not working anymore.
Could anyone here please help me I would like to get from which sender the email delivery is failed.
Thank you in advance.
The PR_TRANSPORT_MESSAGE_HEADERS property contains the same Diagnostic information shown in the body. You just need to read it using the PropertyAccessor class and parse the string with From and To entries.
Outlook.PropertyAccessor oPA = reportItem.PropertyAccessor;
string transportHeaders = (string)oPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");
I'm trying to connect to an rtmps server using C# and FluorineFX.
I'm doing this using this code
netConnection = new NetConnection();
netConnection.OnConnect += onConnect;
netConnection.NetStatus += netStatus;
netConnection.ObjectEncoding = ObjectEncoding.AMF3;
Console.WriteLine(netConnection.PlayerVersion = "WIN 10,1,85,3");
netConnection.Connect("rtmps://example.com:2099/");
example.com is replacing the real url in this example.
But this code only gives me an exception stating that:
System.UriFormatException: One of the identified items was in an invalid format
the FluorineFX webpage states that it supports rtmps, so i would think that would be the case. Any help would be greatly appreciated.
I found a github repo that adds RTMPS support into FlourineFX
https://github.com/epicvrvs/FluorineFXMods
All you need to do is follow the instructions in the top and compile it.
I have a simple application written that allows users to pick inventory items with checkboxes. When the items are checked a textbox is populated showing the user's input. I would like to have a class that would take the contents of the textbox and copy it to a new outlook email with the TO address pre-populated with myemail#gmail.com. ASP.Net is foreign to me and I am a very new C# coder SO I have no idea how to do this. Any ideas.
I have seen an example online as follows...
System.Web.Mail.MailMessage message=new System.Web.Mail.MailMessage();
message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1 );
message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername","SmtpHostUserName" );
message.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword","SmtpHostPassword" );
message.From="from e-mail";
message.To="to e-mail";
message.Subject="Message Subject";
message.Body="Message Body";
System.Web.Mail.SmtpMail.SmtpServer="SMTP Server Address";
System.Web.Mail.SmtpMail.Send(message);
but I have errors everywhere and think that I'm not implementing this right. Is there a simpler way to do this or just a way I might be able to understand. Thanks to any and all answers. I can only check one but I appreciate them all.
http://support.microsoft.com/kb/310263
I am guessing you are not using the Outlook object library. If you want to, then the code is right there.
The only change you will have to make will be
oMsg.Body = TextBox1.text;
where TextBox1 has the all the contents that you wanted to send as the message body.
I'm looking for help from anyone who's worked with the verbot sdk.
I'm making a program that I want to use the LearnedKnowledge.vkb, Teacher.vkb, and any standard bot (julia, for example). Those who've used this before will know that with the rules in Teacher, you can essentially write responses to things that the bot doesn't understand, and train it on the fly.
I'm planning on using speech recognition and text-to-speech, but my problem right now is that after I load the knowledgebases, I can't seem to get any response from the bot.
Here's what I have: The Verbot5Library.dll, from verbots.sourceforge.net (I got the editor and player too, to make sure the files were working). In my program, I set up the variables as such:
Verbot5Engine verbot = new Verbot5Engine();
KnowledgeBase kb = new KnowledgeBase();
KnowledgeBaseItem kbi = new KnowledgeBaseItem();
State state = new State();
XMLToolbox xmlToolboxKB = new XMLToolbox(typeof(KnowledgeBase));
Then I initialize the verbot engine and load the kbs:
// using the xmlToolboxKB method I saw in this forum: http://www.verbots.com/forums/viewtopic.php?t=2984
kbi.Fullpath = #"C:\\[full path to kb...]\\";
kbi.Filename = "LearnedKnowledge.vkb";
kb = (KnowledgeBase)xmlToolboxKB.LoadXML(kbi.Fullpath + kbi.Filename);
verbot.AddKnowledgeBase(kb, kbi);
kbi.Filename = "julia.vkb";
kb = (KnowledgeBase)xmlToolboxKB.LoadXML(kbi.Fullpath + kbi.Filename);
verbot.AddKnowledgeBase(kb, kbi);
//trying to use LoadKnowledgeBase and LoadCompiledKnowledgeBase methods: verbot.LoadKnowledgeBase("C:\\[full path to kb...]\\LearnedKnowledge.vkb");
//verbot.LoadCompiledKnowledgeBase("C:\\[full path...]\\julia.ckb");
//verbot.LoadCompiledKnowledgeBase("C:\\[full path...]\\Teacher.ckb");
// set up state
state.CurrentKBs.Add("C:\\[full path...]\\LearnedKnowledge.vkb");
state.CurrentKBs.Add("C:\\[full path...]\\Teacher.vkb");
state.CurrentKBs.Add("C:\\[full path...]\\julia.ckb");
Finally, I attempt to get a response from the verbot engine:
Reply reply = verbot.GetReply("hello", state);
if (reply != null)
Console.WriteLine(reply.AgentText);
else
Console.WriteLine("No reply found.");
I know julia has a response for "hello", as I've tested it with the editor. But all it ever returns is "No reply found". This code has been taken from the example console program in the SDK download (as very little documentation is available). That's why I need some pointers from someone who's familiar with the SDK.
Am I not loading the KBs correctly? Do they all need to be compiled (.ckb) instead of the XML files (.vkb)? I've used the verbot.OnKnowledgeBaseLoadError event handler and I get no errors. I even removed the resource file Default.vsn needed to load the Teacher, and it throws an error when trying to load it so I'm pretty sure it's all loading correctly. So why do I always get "No reply found"?
resolved: see http://www.verbots.com/forums/viewtopic.php?p=13021#13021
For some reason i am recieving Smtp does not exist in the current context, im using the name space 'using System.Net.Mail;'. I have no idea why and have tried using System.Web.mail;. Hope you can help.
MailMessage mail = new MailMessage();
SmtpClient SmtpMail = new SmtpClient();
SmtpMail.Credentials = new System.Net.NetworkCredential("username", "password");
mail.From = ""; //Error 1 Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
mail.To = ""; // Error 2 Property or indexer 'System.Net.Mail.MailMessage.To' cannot be assigned to -- it is read only
// Error 3 Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddressCollection'
mail.Subject = "password";
mail.Body = "test";
SmtpMail.SmtpServer = "smtp.brad.ac.uk"; // Error 4 'System.Net.Mail.SmtpClient' does not contain a definition for 'SmtpServer' and no extension method 'SmtpServer' accepting a first argument of type 'System.Net.Mail.SmtpClient' could be found (are you missing a using directive or an assembly reference?)
SmtpMail.Send(mail);
SmtpMail is marked as obsolete in newer frameworks. SmtpClient is the recommended class. Maybe this is causing your issue?
EDIT: you can either point to a lower framework in your project, or swap out the class. Either one should work for you. (http://msdn.microsoft.com/en-us/library/system.web.mail.smtpmail.aspx)
EDIT: This class was last supported in .Net 1.1 It will give a complier warning in every framework afterwards.
Add a reference to System.Web to your project, as well as a using System.Web.Mail and see if that helps. I'd have added this as a comment on qor72's answer, but I don't have the rep yet.
Sounds like you are missing a reference to System.Net.Mail in your project. Add it in as a reference and see if that gets you further.
EDIT: Fixed reference to get to System.Net.Mail.SmtpClient.
For errors 1,2, and 3, instantiate MailMessage like so: MailMessage mail = new MailMessage("string of sender", "string of acceptor");
For error 4, try using the Host property or ServicePoint instead.