How to Send an Email with Attachments in ASP.NET Core

  Рет қаралды 35,107

Code Maze

Code Maze

Күн бұрын

Пікірлер: 93
@CodeMaze
@CodeMaze 9 ай бұрын
Thank you all for watching and for your support. ►► If you want to check out all our courses you can do that here: courses.code-maze.com/courses/
@Haseeb-Champion
@Haseeb-Champion 6 ай бұрын
dear sir !!!1 i need to send data in html form in email pleas as soon as possible response me which file i need to costomise for this solution and if you are free than share a code of lines how i can send data in html form please tahnks
@sargon4307
@sargon4307 2 жыл бұрын
Im not exagerating that ur channel and pages are the bigigest source of aspnet learning i have ever found.
@CodeMaze
@CodeMaze 2 жыл бұрын
Thanks a lot. We are glad you find our resources useful.
@mazlumorhan
@mazlumorhan 2 жыл бұрын
Oh man , your explanation was perfect ! I'll try it ride the away
@CodeMaze
@CodeMaze 11 ай бұрын
Thanks! Much appreciated!
@oguz40
@oguz40 4 жыл бұрын
Beautiful, everything we need know about sending emails is here
@CodeMaze
@CodeMaze 4 жыл бұрын
Thanks a lot. We appreciate that.
@edwinjesus5369
@edwinjesus5369 2 жыл бұрын
Excelent my friend, grettings from Peru....
@CodeMaze
@CodeMaze 2 жыл бұрын
Thank you very much! Regards as well.
@JoseAlvarez-dl3hm
@JoseAlvarez-dl3hm 4 жыл бұрын
It totally worked! Thanks a lot mate. I had a handshakingexcpetion problem at the beginning but you just need to configure that part in your email account so it can handle it and also take special care about the port you are using, since some are targeting SSL and others the protocol TLS, in this case we should aim at SSL since we are not handling valid certificates or we are generating our own which are not accepted usually, but useful at the dev stage. 465 (SSL), 587 (TLS) these are the port numbers for their respective protocols, TLS is more restrictive.
@CodeMaze
@CodeMaze 4 жыл бұрын
Thank you very much for the comment and clarification. I am glad the video helped you.
@futureex7313
@futureex7313 3 жыл бұрын
It worked like a charm from the first try. Thank you very much!
@CodeMaze
@CodeMaze 3 жыл бұрын
You're welcome!
@ianthomas7703
@ianthomas7703 3 жыл бұрын
Superb video - makes the process clear and if you just want to copy the code thats an option too. We had one issue with the port which was different; for office 365 but am sure most people will work this out. thanks a million guys
@CodeMaze
@CodeMaze 3 жыл бұрын
Glad it helped. Thank you too for watchng the video.
@nahuelriquelme6250
@nahuelriquelme6250 8 ай бұрын
The best channel.
@CodeMaze
@CodeMaze 8 ай бұрын
Thanks a lot. I'm glad you like it.
@coskungulcicek
@coskungulcicek 3 жыл бұрын
thank you brother. you are the best.
@CodeMaze
@CodeMaze 3 жыл бұрын
You're most welcome
@markoradojevic9690
@markoradojevic9690 4 жыл бұрын
Great content, nice explanation and most importantly you cover more than just one thing. Keep up the good work!
@CodeMaze
@CodeMaze 4 жыл бұрын
Thank you Marko a lot. I hope you follow us on our blog since you can find a lot more content there (which we believe is good as well :D :D ) All the best.
@digitaldaridesatv1545
@digitaldaridesatv1545 4 жыл бұрын
Thank you so much, this is what I want. I've done to test.
@CodeMaze
@CodeMaze 4 жыл бұрын
Thank you very much. Glad we could help!
@DooM-mn8cc
@DooM-mn8cc 3 жыл бұрын
I love your blogs and it was great to find this channel, I have a question is this has some limitation like 50,000 email only per day then you have to pay?
@CodeMaze
@CodeMaze 3 жыл бұрын
Not that I know of. This channel is something we just treid, we are still mainly dedicated to blogging.
@szafar5797
@szafar5797 4 жыл бұрын
Thanks got it working nice video
@CodeMaze
@CodeMaze 4 жыл бұрын
Welcome 👍
@taneujin88
@taneujin88 3 жыл бұрын
Thank you for the video. my project does not have the Weatherforecasr controller, it will be nice if you could show how to do it by adding a new controller, instead of modifying the Weatherforecast. BTW, is there a reason you chose to modify the existing controller?
@CodeMaze
@CodeMaze 3 жыл бұрын
It really has nothing to do with any controller. You can add new, you can modify the existing one... The important part is how to call email service and pass the Message object, which again has nothing to do with a controller itself. Just add the email service through the DI and use it in any action as I did. That's all that matters.
@anhminh5479
@anhminh5479 4 жыл бұрын
Thanks for tutorial! but we need turn on "less secure apps" on gmail to do this
@CodeMaze
@CodeMaze 4 жыл бұрын
That is correct. Google has its own security protocols.
@rainn2115
@rainn2115 4 жыл бұрын
Hi, are you testing the code in postman? As when I run the sample code in debug mode I only see the black console window.
@CodeMaze
@CodeMaze 4 жыл бұрын
As you can see in the video, or in the article linked in the description, we are using Postman to test our API endpoints.
@khumozin
@khumozin 4 жыл бұрын
I'm getting this error: MailKit.Security.SslHandshakeException: An error occurred while attempting to establish an SSL or TLS connection.
@CodeMaze
@CodeMaze 4 жыл бұрын
Well, without your code, it is hard for me to tell you why do you have that error. But maybe this official documentation can help you: github.com/jstedfast/MailKit/blob/master/FAQ.md#SslHandshakeException
@szafar4789
@szafar4789 3 жыл бұрын
How can u add a file as a attachment using a variable that has the file name path
@pejvakco
@pejvakco 3 жыл бұрын
Greate Thanks
@CodeMaze
@CodeMaze 11 ай бұрын
Glad it helped!
@Hawtep
@Hawtep 3 жыл бұрын
Thank you sir
@CodeMaze
@CodeMaze 3 жыл бұрын
You are very welcome.
@A_walk_in_the_park
@A_walk_in_the_park 3 жыл бұрын
Hello, my question is how could I embed the image into the mail rather than having it appear as an attachment. cid:image_name doesn't seem to work at all, as it appears as an attachment. Thank you for your answer.
@CodeMaze
@CodeMaze 3 жыл бұрын
As you can see, you can use pure HTML for the Email body. So there you can use the img element and add your picture for sure.
@A_walk_in_the_park
@A_walk_in_the_park 3 жыл бұрын
@@CodeMaze sorry I have been a bit vague with my question. Let me give some context. I am using sendgrid templates and in my controller I am only passing through the handlebar parameteres. One of those parameters is image. I wonder if it's even possible to pass a HTML tag through. Issue is that the image is stored in my database, so I can't pass through a https... link, but a local path... Just googled if it's possible and it is, so thank you 😁
@AnkproTraining
@AnkproTraining 3 жыл бұрын
@@A_walk_in_the_park Convert to base64 format and at the string to the image tag
@BryantStewart
@BryantStewart 4 жыл бұрын
Suppose I do not want to pass the receiver's mail by string, I want to take it from a list that will be seen on the frontend or send it to several recipients, how do I do this?
@CodeMaze
@CodeMaze 4 жыл бұрын
You have to add a custom logic for that. Either use query strings (or one query string with multiple email addresses and then parse it on the server), or you can send recepients (as you select them) to the server, store them somewhere of your choice and then send another request with attachments.
@Godfadda
@Godfadda 2 жыл бұрын
Unfortunately, this no longer works with Gmail externals as Google as shut down all external applications from interacting with email addresses
@CodeMaze
@CodeMaze 2 жыл бұрын
Yeah, from the 30th May this feature is disabled by Google. But there is a way by using the App Passwords feature. All you have to do is to first enable 2 factor auth for your google account (it is quite an easy process and you can find tutorials on google how to do that). Once you do that, the App Passwords option will be enabled for you. So you have to click on it, choose select app and choose the Other (custom name). Then just add any name you want and generate the password. All you have to do is to use that password with the email sender app instead of your personal one. After you do that, everything will work just fine. Just tested it.
@Godfadda
@Godfadda 2 жыл бұрын
@@CodeMaze thank you so much!
@adamm9706
@adamm9706 4 жыл бұрын
I'm getting the warning that MailboxAddress(String) is obsolete, and looking at the mimeKit.net web site says to use one of the four other options. How can I do this? Link: www.mimekit.net/docs/html/T_MimeKit_MailboxAddress.htm
@CodeMaze
@CodeMaze 4 жыл бұрын
I must ask where did you find the Message.Message code in the video or in the source code?
@adamm9706
@adamm9706 4 жыл бұрын
@@CodeMaze I updated the prev comment as well. The warning starts in the Message.cs class when you create the constructors to property. To.AddRange(to.Select(x => new MailboxAddress(x))); 3:18 is where you started it.
@CodeMaze
@CodeMaze 4 жыл бұрын
I am really not sure why you have that warning message. In the video, we are using the latest NetCore.MailKit library version 2.0.3 and as you can see, there is no such error. You can visit our article and download the source code to compare it with yours. Are you using the right library? This is really strange.
@adamm9706
@adamm9706 4 жыл бұрын
@@CodeMaze latest version of MailKit is 2.8.0 The docs say that MailboxAddress(String) is going away and to use MailboxAddress(String, String).(www.mimekit.net/docs/html/T_MimeKit_MailboxAddress.htm) How would I implement the MailBoxAddress(String, String) Class? thanks for your responses!
@CodeMaze
@CodeMaze 4 жыл бұрын
No, you are installing the wrong library. Please watch the video again, you will se we install the www.nuget.org/packages/NETCore.MailKit/2.0.3
@Haseeb-Champion
@Haseeb-Champion 6 ай бұрын
thanks a lot dear sir may you live long but my destination account have not receiving mail from my sender mail account
@CodeMaze
@CodeMaze 6 ай бұрын
Hi. Thanks for the nice wishes. To be honest I am using this project as a base for all my email-based videos and projects and I don't have any issues with sending or receiving emails. I am not sure what issue are you facing but, if you check, for example the 2FA video, you will see I use there the same email sender project, so you can always use the source code to see what is different in your project.
@amirbeygi908
@amirbeygi908 2 жыл бұрын
i have a question , now google turn off less secure , this method still working ? if not what should we do ?
@CodeMaze
@CodeMaze 2 жыл бұрын
Hello Amir. Have you tried it? I did two weeks ago and everything is still working. Just with a new version of Mailkit, you need to provide an additional parameter for the MailboxAddress constructor. You can read more in our article.
@amirbeygi908
@amirbeygi908 2 жыл бұрын
​@@CodeMaze Hi, thank you very much yes, it was solved, the main problem created by gmail solved by getting a two-step password and the rest was executed correctly, thank you
@accrtest1568
@accrtest1568 4 жыл бұрын
Hi there can you please assist me with the following error: SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
@CodeMaze
@CodeMaze 4 жыл бұрын
Hi. The only connection our application establishes is the one with SMTP server. So maybe you have wrong credentials or something. I really can't help you more without any further details.
@lucadiaddezio6958
@lucadiaddezio6958 4 жыл бұрын
@@CodeMaze Hi, Thanks for the amazing tutorial, my Google Account says that my .net application is not a safe applications and it blocks me... how can I do? Thanks again
@CodeMaze
@CodeMaze 4 жыл бұрын
We explained that in the video. You need to allow less secure applications for your google account. Once you do that, it will work.
@accrtest1568
@accrtest1568 4 жыл бұрын
@@CodeMaze My particular problems had to do with antivirus software(AVG) blocking the connections - Had to uninstall and everything worked perfectly.
@kakhachaduneli5296
@kakhachaduneli5296 4 ай бұрын
'MailboxAddress' does not contain a constructor that takes 1 arguments - I couldn't do anything about the MailboxAddress problem, how can I fix it? :( :(
@CodeMaze
@CodeMaze 4 ай бұрын
This is how you can resolve that issue using the newest version of the library: emailMessage.From.Add(new MailboxAddress("email", _emailConfig.From));
@shreenkhalaverma7949
@shreenkhalaverma7949 4 жыл бұрын
could you help me with this? : 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: EmailService.IEmailSender Lifetime: Scoped ImplementationType: EmailService.EmailSender': Unable to resolve service for type 'EmailService.EmailConfiguration' while attempting to activate 'EmailService.EmailSender'.)'
@CodeMaze
@CodeMaze 4 жыл бұрын
Hi. Well you have an error while registering the IEmailSender service in the Startup class. I am not sure what you did there, so can't tell you more abou it. But what I can tell you is to navigate to our blog post (the link is in the description of the video), download our source code and then compare it to yours. You have probably missed something small but it always looks like a large problem :)
@ikryper
@ikryper 4 жыл бұрын
I noticed I had the same issue, double check his code, I put services.AddSingleton("emailConfig") when it should have quotes, I must have been tired when following along
@ovo-aeon
@ovo-aeon 4 жыл бұрын
there is this nice looking email u get from banks nd other establishments, that are not just plain text how do you expand this tutorial to achieve that, thank you
@CodeMaze
@CodeMaze 4 жыл бұрын
Hi Alex. As you can see from this video, you can have HTML as the body of your email instead of the plain text. That said, you can create an html document with all the headers and stuff and use it as a body for your email message.
@stefanomattiatroisi2018
@stefanomattiatroisi2018 2 жыл бұрын
Actually with the version of MailKit to 2.1.0, new MailboxAddress doesn't take anymore only one argument, you need to provide the name and the email.
@CodeMaze
@CodeMaze 2 жыл бұрын
Yeah, you are right. The article on the same topic, that we attached in the description section is updated with the source code. It is a bit harder with the video updates. Anyway, you can either provide two parameters as you stated in the constructor, or you can use a parameterless constructor and then just use the required property with a created object.
@edwinjesus5369
@edwinjesus5369 2 жыл бұрын
I will have problems with System.Net.Mail; only in localhost, not function in azure o cloud server... with you example yes function in cloud... excelent
@CodeMaze
@CodeMaze 2 жыл бұрын
Glad to hear that. This is always great to know.
@mouneshhb7389
@mouneshhb7389 4 жыл бұрын
thanks for the video, it could have been little bit more informative instead of rapid explanation
@CodeMaze
@CodeMaze 4 жыл бұрын
For more information, you can always read the article on the same topic. The link is in the description.
@szafar5797
@szafar5797 4 жыл бұрын
I follow your video but it never worked.
@CodeMaze
@CodeMaze 4 жыл бұрын
I am not sure that anyone can help you with the comment like that. As you can see in the video, it works for sure, if you read the article we linked, you will see it works. If you download the source code you will see it works. So, you are doing something wrong for sure, and if you want any help, some error description would be always appreciated.
@johnkanekunga6668
@johnkanekunga6668 4 жыл бұрын
.NET is just too much coding for a simple task!
@CodeMaze
@CodeMaze 4 жыл бұрын
Well, I don't know what to say to that :D I can't compare it. Basically, we teach our viewers and readers .NET and how to do things with .NET. If it has to use more code lines than Java or PHP, well, unless it is our implementation error, we can't do much about it.
@MahanadhiNayagan
@MahanadhiNayagan Жыл бұрын
Hi CodeMaze! Is the code is supported for .net core 6? I'm getting the below error "System.MissingMethodException: Method not found: 'Void MimeKit.MailboxAddress..ctor(System.String)'. at EMailService.Message.c.b__12_0(String x) at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext() at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection) at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)" I'm using NETCore.Mailkit 2.0.2 version
@CodeMaze
@CodeMaze Жыл бұрын
Hi. Yes, it definitely is. We use the same service in our Premium verision of the Web API books, and this is in .NET 8. So everything must work. That said, I am really not sure, why you get this error. You can always check with our source code and compare with your solution.
Sending Email in C# using FluentEmail
30:36
IAmTimCorey
Рет қаралды 92 М.
Sending Emails in ASP.NET Core using Gmail | Quick, Free and Easy
9:46
Programming with Felipe Gavilan
Рет қаралды 1,8 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
How to send an email in C# with .NET using Mailkit
16:46
tutorialsEU
Рет қаралды 34 М.
Is Blazor Better than React?
14:25
Gavin Lon
Рет қаралды 56 М.
how to send email in asp.net mvc | MVC sending email
12:36
Haritha Computers & Technology
Рет қаралды 35 М.
Scheduling Background Tasks In .NET With Quartz
10:51
Milan Jovanović
Рет қаралды 42 М.
ASP.NET Core Authentication with JWT and Angular - Part1
13:47
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 302 М.
Implementing JWT Authentication in ASP.NET Core
23:51
Nick Chapsas
Рет қаралды 48 М.