Click here to Skip to main content
16,020,186 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

why to send email italian PEC with asp.net?

With my code it doesn't send emails

thanks
Best regards
Salvo

What I have tried:

VB
Dim myMail As New MailMessage()
Dim fromEmail As String = "emailpec"
Dim toEmail As String = "emailpec"
Dim mySmtp As New SmtpClient("smtppec")

mySmtp.UseDefaultCredentials = False
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
mySmtp.Port = 465
mySmtp.EnableSsl = True
mySmtp.Credentials = New System.Net.NetworkCredential(fromEmail, "PASSWORD")

myMail.From = New MailAddress(fromEmail)
myMail.To.Add(toEmail)

myMail.Subject = "test send pec"

myMail.IsBodyHtml = True

myMail.Body = "test send PEC"

mySmtp.Send(myMail)
Posted
Updated 6-Feb-24 5:41am
v2
Comments
Richard Deeming 6-Feb-24 6:17am    
Aside from the fact that "emailpec" is not a valid email address, and "smtppec" is almost certainly not a valid SMTP server, nobody here can guess what the problem is.

You need to contact the people who run your SMTP server to find out why your emails aren't being sent. There are dozens of possible problems, so you'll almost certainly need the exact error details and/or the network logs of the SMTP session to diagnose the problem.

You might also want to check the name of the SMTP server. You have to use a fully qualified DNS name for the server, which is most definitely NOT "smtppec". You can get the correct name from the documentation of whatever mail service or ISP you're using.
 
Share this answer
 
The most likely reason is simply that emailpec is not a valid email address, which is always of the form username@domain
Without a valid to and from email address, nothing is going to happen.

I'd also check your password, and your protocol type / port info
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900