Error on client.send

Hi,

I have an error everything the "client.send" functionality is call and the error has no message.

Please take a look of the function below and could you tell me what I do wrong?

Public Shared Sub SendMail(ByVal docContent As Byte(), ByVal imagePath As String, ByVal fromEmail As String, ByVal toEmail As String, ByVal ccEmail As String, ByVal bccEmail As String, ByVal subjectText As String)

Try

Dim licenseDoc As Aspose.Words.License

Dim licenseNetwork As Aspose.Network.License

licenseDoc = New Aspose.Words.License

licenseDoc.SetLicense(imagePath & "\Aspose.Total.lic")

licenseNetwork = New Aspose.Network.License

licenseNetwork.SetLicense(imagePath & "\Aspose.Total.lic")

Dim docDocument As Document

'save html to stream and images to folder

Dim stream As MemoryStream = New MemoryStream()

docDocument = GetDocument(docContent)

docDocument.SaveOptions.ExportImagesFolder = imagePath & "\WordDocs"

docDocument.Save(stream, SaveFormat.Html)

'get html code from stream

stream.Position = 0

Dim reader As StreamReader = New StreamReader(stream)

Dim htmlBody As String = reader.ReadToEnd()

Dim msg As Mail.MailMessage = New Mail.MailMessage(fromEmail, toEmail)

'add embedded images

Dim imageNames As String() = Directory.GetFiles(imagePath)

Dim i As Integer = 0

Dim j As Integer = 0

For i = 0 To (imageNames.Length - 1)

htmlBody = htmlBody.Replace(imageNames(i), "cid:" + Path.GetFileNameWithoutExtension(imageNames(i)))

Dim image As Mail.LinkedResource = New Mail.LinkedResource(imageNames(i), Mime.MediaTypeNames.Image.Jpeg)

image.ContentId = Path.GetFileNameWithoutExtension(imageNames(i))

msg.LinkedResources.Add(image)

Next

'send mail

'msg.To.Add(toEmail)

If ccEmail <> "" Then msg.CC.Add(ccEmail)

If bccEmail <> "" Then msg.Bcc.Add(bccEmail)

msg.HtmlBody = htmlBody

msg.Subject = subjectText

Dim client As Mail.SmtpClient = New Mail.SmtpClient(GetConfigValue("SmtpServer")) ' "Host", "Username", "password")

client.Send(msg)

'remove images

For j = 0 To (imageNames.Length - 1)

File.Delete(imageNames(i))

Next

licenseDoc = Nothing

licenseNetwork = Nothing

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

_________________________________________________________________

Thanks,

Tan Quan

Hello,

Here are the trouble-shotting steps

1) Please call the Mail.MailMessage.Save(filename) function to save the mail message to eml formate, and send me this message for debugging.

2) Please print out the Exception.ToString(), and send me.

3) You can attach the eml file and Exception.ToString on this thread or send me an email (guangzhou$$aspose.com)

Thanks for your helps

Hi,

1) Please call the Mail.MailMessage.Save(filename) function to save the mail message to eml formate, and send me this message for debugging. -> I have no error message when I save to eml format

2) Please print out the Exception.ToString(), and send me. -> I have this Error-> Value cannot be null. Parameter name: Username should not be null

3) You can attach the eml file and Exception.ToString on this thread or send me an email (guangzhou$$aspose.com)

Thanks,

Tan Quan

Hi,

I can send email with the function below but not with ASPOSE.Network.Mail:

_______________________________________________________

Public Shared Sub SendMail2(ByVal fromEmail As String, ByVal toEmail As String, ByVal ccEmail As String, ByVal bccEmail As String, ByVal subjectText As String, ByVal bodyText As String, ByVal bodyFormat As Boolean)

Dim oMail As New MailMessage

'Dim sSmtpServer As String

Dim mSmtpClient As SmtpClient

Try

''// This configuration is for development. It is not required on staging and production

'oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

''// Name or IP of remote SMTP server

'oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP.IMF.ORG"

''// Server port

'oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'oMail.Configuration.Fields.Update()

oMail.From = New MailAddress(fromEmail)

If toEmail <> "" Then oMail.To.Add(toEmail)

If ccEmail <> "" Then oMail.CC.Add(ccEmail)

If bccEmail <> "" Then oMail.Bcc.Add(bccEmail)

oMail.Body = bodyText

oMail.Subject = subjectText

'oMail.Priority = MailPriority.Normal

oMail.IsBodyHtml = bodyFormat

mSmtpClient = New SmtpClient(GetConfigValue("SmtpServer"))

mSmtpClient.Send(oMail)

oMail = Nothing

Catch ex As Exception

Throw New Exception(ex.ToString)

End Try

End Sub

__________________________________________________________

Could you help me on that?

Best,

Tan Quan

Please make sure you create the SmtpClient with proper settings, like Host name and user name. From the error message, it looks like the smtpclient errors.

Could you help to check that? What's the GetConfigValue("SmtpServer") returns?

Thanks

Hi,

When I convert from Word document to html, all the html images (from many html file) are save a the same folder.

How do I know which images belong to which html file?

Could you give to me a sample of code? The sample that you give it to me assume only for 1 user and how about for multiple users that save image to the same folder

Thanks,

Tan Quan

Hi,

I was able to make it work on smtp.

When I convert from Word document to html, all the html images (from many html file) are save a the same folder.

How do I know which images belong to which html file?

Could you give to me a sample of code? The sample that you give it to me assume only for 1 user and how about for multiple users that save image to the same folder

Thanks,

Tan Quan