Click here to Skip to main content
15,747,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i need to send the mail from my project in VB.Net


how to write the generic code for all domain

main problem is not able to send the mail from yahoo and other domains expect gmail

From gmail case it work
From yahoo or hotmail it not work

the sender domain is get from user so need the generic code for send to one domain another one

Error msg : failure sending mail 


VB
Public Function Mailing_Document()

        Dim message As System.Net.Mail.MailMessage

        '  Dim smtp As New System.Net.Mail.SmtpClient("smtp.gmail.com", 587)

        Dim smtp As New System.Net.Mail.SmtpClient("smtp.mail.yahoo.com", 465)

        Dim attach As System.Net.Mail.Attachment

        Dim sFrom As String, sTo As String, sSsub As String, sMsg As String

        Dim sFile As String

        '  sFrom = "mailagain@gmail.com"

        sFrom = "mailagain@yahoo.in"

        sTo = "mailme@gmail.com"

        sFile = "C:\Documents and Settings\Admin\Desktop\document.pdf"

        sSsub = "PO_Invoice-Detail"

        sMsg = "Ref the Attachment for detail of invoice"


        message = New System.Net.Mail.MailMessage(sFrom, sTo, sSsub, sMsg)
        message.Bcc.Add("mailmeonce@yahoo.in") '
        message.CC.Add("mailonceagain@gmail.com") '

        If My.Computer.FileSystem.FileExists(sFile) Then

            attach = New System.Net.Mail.Attachment(sFile)

            message.Attachments.Add(attach)

        End If

        smtp.EnableSsl = True


        smtp.Credentials = New System.Net.NetworkCredential(sFrom, "chhhe12")


        Try

            smtp.Send(message)

            MessageBox.Show("Well, the mail message appears to have been a success!", " Successful?", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Catch exc As Net.Mail.SmtpException
            MessageBox.Show(exc.StatusCode.ToString, " Something Happened?", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try


    End Function
Posted
Updated 23-Jul-12 1:54am
v2
Comments
nithumca 23-Jul-12 8:22am    
sorry it not work

1 solution

 
Share this answer
 
Comments
StianSandberg 23-Jul-12 8:06am    
5: A few good links there..
Raghunatha_Reddy_S 23-Jul-12 8:06am    
:-)
_Amy 23-Jul-12 8:15am    
Thank you AlluvialDeposit & srnr.. :)

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