Op een server heb ik een VB6 programma die probleemloos mails verstuurt. Dit doe ik als volgt :
Private Sub SendMail(From As String, ToEmail As String, Subject As String, BodyStr As String)
Set objNewMail = CreateObject("CDONTS.NewMail")
If cboFormaat.Text = "HTML" Then
objNewMail.BodyFormat = 0
objNewMail.MailFormat = 0
Else
objNewMail.BodyFormat = 1
objNewMail.MailFormat = 1
End If
Select Case cboPrioriteit.Text
Case "Laag"
objNewMail.Send From, ToEmail, Subject, BodyStr, 0
Case "Normaal"
objNewMail.Send From, ToEmail, Subject, BodyStr, 1
Case Else
objNewMail.Send From, ToEmail, Subject, BodyStr, 2
End Select
Set objNewMail = Nothing
End Sub
Nu schrijf ik mij eerste C# programma en ook dit programma moet mails versturen. Dit lukt echter niet (is op dezelfde server geïnstalleerd als het VB6 programma !).
Ik doe het als volgt :
public static void CreateMessageWithAttachment(string Van, string Naar, string Onderwerp, string Bericht, string file)
{
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
Van,
Naar,
Onderwerp,
Bericht);
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
//Send the message.
SmtpClient client = new SmtpClient("127.0.0.1");
// Add credentials if the SMTP server requires them.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
try
{
client.Send(message);
}
catch (Exception ex)
{
MessageBox.Show("Exception caught in CreateMessageWithAttachment() :" + ex.ToString());
}
data.Dispose();
}
De foutboodschap die ik krijg is System.Net.Mail.SmtpFailedRecipientException : Mailbox unavailable. The server response was 5.7.1 Unabled to relay for...
Wie kan mij helpen ?
Private Sub SendMail(From As String, ToEmail As String, Subject As String, BodyStr As String)
Set objNewMail = CreateObject("CDONTS.NewMail")
If cboFormaat.Text = "HTML" Then
objNewMail.BodyFormat = 0
objNewMail.MailFormat = 0
Else
objNewMail.BodyFormat = 1
objNewMail.MailFormat = 1
End If
Select Case cboPrioriteit.Text
Case "Laag"
objNewMail.Send From, ToEmail, Subject, BodyStr, 0
Case "Normaal"
objNewMail.Send From, ToEmail, Subject, BodyStr, 1
Case Else
objNewMail.Send From, ToEmail, Subject, BodyStr, 2
End Select
Set objNewMail = Nothing
End Sub
Nu schrijf ik mij eerste C# programma en ook dit programma moet mails versturen. Dit lukt echter niet (is op dezelfde server geïnstalleerd als het VB6 programma !).
Ik doe het als volgt :
public static void CreateMessageWithAttachment(string Van, string Naar, string Onderwerp, string Bericht, string file)
{
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
Van,
Naar,
Onderwerp,
Bericht);
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
//Send the message.
SmtpClient client = new SmtpClient("127.0.0.1");
// Add credentials if the SMTP server requires them.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
try
{
client.Send(message);
}
catch (Exception ex)
{
MessageBox.Show("Exception caught in CreateMessageWithAttachment() :" + ex.ToString());
}
data.Dispose();
}
De foutboodschap die ik krijg is System.Net.Mail.SmtpFailedRecipientException : Mailbox unavailable. The server response was 5.7.1 Unabled to relay for...
Wie kan mij helpen ?