Question Send emails with attachments

jonny22

Member
Joined
May 14, 2022
Messages
15
Programming Experience
1-3
Hello everyone, I'm trying to send emails with attachments with C #, I saw that there is a special "System.Net.Mail" method, I tried to ascribe the code myself and also to use code examples that I found on the net but i can't get them to work, debugging with visual studio always returns several errors, which i am unable to fix, can someone point me to a working code example? Or a well done tutorial to be able to write working code?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
I suggest installing SMTP4DEV (or running a container with it). Try sending email to that local test server without authentication. When that is working, enable authentication on it. Once that it working, then try using with that mail host that is failing.

Testing with the local server first will help you iron out any issues that might be related to your code. Switching to the actual mail host will then just be a configuration change of server name, port, and credentials. In theory, it should just work.

If that doesn't work, then it is time to fire up WireShark or your favorite network sniffer. Unfortunately, I am out of my depth in guiding you what to look for in the packets to determine why it is closing the connection.
 

jonny22

Member
Joined
May 14, 2022
Messages
15
Programming Experience
1-3
First of all, thank you for the help you are giving me!
I installed the local server you recommended.
I see the port on which it is listening but I did not understand what the name of this server is, which I then have to put in the C # code to send the email, what is the exact name of the SMTP4DEV local server?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
It will be your machine name or localhost.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
Either one should work. You can also use your machine name as a third option.
 
Top Bottom